如何将 Maven 依赖项下载为 *.jar 文件?

How to download maven dependency as *.jar file?

我尝试实现 here 中的示例,但是在安装 Maven 依赖项后,我无法在下载的依赖项中找到 jar 文件。

我的 pom.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- This is often your domain name (reversed.)  -->
    <groupId>com.abc</groupId>
    <!-- The name of this project (actually, the name of the artifact, which is the thing that this project produces. A jar in this case.) -->
    <artifactId>javaparser-maven-sample</artifactId>
    <!-- The version of this project. SNAPSHOT means "we're still working on it" -->
    <version>1.0-SNAPSHOT</version>

    <properties>
        <!-- Tell Maven we want to use Java 8 -->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- Tell Maven to treat all source files as UTF-8 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <geotools.version>2.5.7</geotools.version>
    </properties>
   <repositories>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net repository</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
        <id>osgeo</id>
        <name>Open Source Geospatial Foundation Repository</name>
        <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>
    <repository> <!--Add the snapshot repository here-->
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>opengeo</id>
        <name>OpenGeo Maven Repository</name>
        <url>http://repo.opengeo.org</url>
    </repository>
</repositories>

    <dependencies>
        <!-- Here are all your dependencies. Currently only one. These are automatically downloaded from https://mvnrepository.com/ -->
        <dependency>
            <groupId>com.github.javaparser</groupId>
            <artifactId>javaparser-core</artifactId>
            <version>3.15.21</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mil.nga.geopackage/geopackage -->
        <dependency>
            <groupId>mil.nga.geopackage</groupId>
            <artifactId>geopackage</artifactId>
            <version>3.5.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.geotools/gt-api -->
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-api</artifactId>
            <version>20.5</version>
        </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.geotools/gt-geometry -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geometry</artifactId>
        <version>2.5-M2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.geotools/gt-referencing -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-referencing</artifactId>
        <version>17.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.locationtech.jts.io/jts-io-common -->
    <dependency>
        <groupId>org.locationtech.jts.io</groupId>
        <artifactId>jts-io-common</artifactId>
        <version>1.16.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.opengis/geoapi -->
    <dependency>
        <groupId>org.opengis</groupId>
        <artifactId>geoapi</artifactId>
        <version>3.0.0</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.geotools/gt-jts-wrapper -->
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-jts-wrapper</artifactId>
    <version>17.0</version>
    <scope>test</scope>
</dependency>
    <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-swing</artifactId>
            <version>17.0</version>
        </dependency>

    
    
    </dependencies>

    <!-- This blob of configuration tells Maven to make the jar executable. You can run it with:
    mvn clean package
    java -jar target/javaparser-maven-sample-1.0-SNAPSHOT-shaded.jar
    -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.abc.conversion.LogicPositivizer</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

除了 geotools 相关的 jar,我可以下载所有的 jar。当我清理并 运行 项目时,在 .m2 文件夹中我看不到与 geotool 相关的 jars。即使在 Maven 存储库中,我也无法下载 jar 文件。

Maven repo

还有其他方法可以继续吗?

如果您在网络浏览器中粘贴 Open Source Geospatial Foundation Repository URL 并按回车键,将会出现 return 404 Not Found 错误。当 Maven 尝试连接到该资源来为您获取依赖项但它不再可用时,就会发生这种情况。但是,如果你密切关注Maven Repo link,有一个注释:

Note: this artefact is located at Boundless repository (https://repo.boundlessgeo.com/main/)

尝试将http://download.osgeo.org/webdav/geotools/替换为注释URL和运行mvn clean install

如果这对你有用,请告诉我。

Boundless 的存储库 运行 已被 OSGeo 托管的存储库取代。 OSGeo webdav 存储库已合并到新的 OSGeo 存储库中。详情在这里 (https://docs.geotools.org/latest/userguide/tutorial/quickstart/maven.html)

替换此块

<repository>
    <id>osgeo</id>
    <name>Open Source Geospatial Foundation Repository</name>
    <url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository> <!--Add the snapshot repository here-->
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
    <id>opengeo</id>
    <name>OpenGeo Maven Repository</name>
    <url>http://repo.opengeo.org</url>
</repository>

  <repository>
    <id>osgeo</id>
    <name>OSGeo Release Repository</name>
    <url>https://repo.osgeo.org/repository/release/</url>
    <snapshots><enabled>false</enabled></snapshots>
    <releases><enabled>true</enabled></releases>
  </repository>
  <repository>
    <id>osgeo-snapshot</id>
    <name>OSGeo Snapshot Repository</name>
    <url>https://repo.osgeo.org/repository/snapshot/</url>
    <snapshots><enabled>true</enabled></snapshots>
    <releases><enabled>false</enabled></releases>
  </repository>