【问题标题】:How to download maven dependency as *.jar file?如何将 maven 依赖项下载为 *.jar 文件?
【发布时间】:2020-06-01 09:00:20
【问题描述】:

我尝试从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 相关的 jar。即使在 Maven 存储库中,我也无法下载 jar 文件。

Maven repo

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

【问题讨论】:

    标签: java xml maven geotools


    【解决方案1】:

    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>
    

    【讨论】:

    • 这不是我之前说过的吗?
    • 没有。您建议的 Boundless repo 已停用。此时,可以在上面列出的 OSGeo 存储库中使用 GeoTools,并在 GeoTools 快速入门中进行了描述。
    【解决方案2】:

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

    注意:此工件位于 Boundless 存储库 (https://repo.boundlessgeo.com/main/)

    尝试将 http://download.osgeo.org/webdav/geotools/ 替换为笔记 URL 中的给定值并运行 mvn clean install

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

    【讨论】:

    • 哪里需要替换http://download.osgeo.org/webdav/geotools/
    • osgeo开源地理空间基础存储库download.osgeo.org/webdav/geotools/</url> url在 标签中
    • 无法解析项目 com.abc:javaparser-maven-sample:jar:1.0-SNAPSHOT 的依赖项:无法在 org.geotools:gt-api:jar:20.5 收集依赖项:读取失败org.geotools:gt-api:jar:20.5 的工件描述符:无法将工件 org.geotools:gt-api:pom:20.5 从/向 osgeo (repo.boundlessgeo.com/main) 传输:repo.boundlessgeo.com:未知主机回购。 boundlessgeo.com
    猜你喜欢
    • 2019-06-20
    • 1970-01-01
    • 2016-01-11
    • 2015-07-12
    • 1970-01-01
    • 2018-12-26
    • 2011-01-13
    • 2021-10-25
    相关资源
    最近更新 更多