设置Maven存储库

时间:2018-11-07 10:16:32

标签: java maven

我的新项目需要javax.xml软件包。我确实在mvnrepository.com中进行了搜索,发现one

<!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api -->
<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>2.0_EA1</version>
</dependency>

我想,第一个注释行是软件包存储库。请,如果我错了,请纠正我。我在pom.xml中添加了以下部分:

<repositories>
  <repository>
    <id>repo1</id>
    <name>Repo 1</name>
    <url>https://mvnrepository.com/artifact/javax.xml/jaxrpc-api</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>2.0_EA1</version>
  </dependency>
</dependencies>

但是看起来我输入了错误的Maven地址。

mvn compile带来了错误:

[ERROR] Failed to execute goal on project test-xpath: Could not resolve dependencies for project com.kkk:test-xpath:jar:0.0.1-SNAPSHOT: Failure to find javax.xml:jaxrpc-api:jar:2.0_EA1 in https://mvnrepository.com/artifact/javax.xml/jaxrpc-api was cached in the local repository, resolution will not be reattempted until the update interval of repo1 has elapsed or updates are forced -> [Help 1]

我做错了什么以及如何解决?

UPD

删除存储库后出现错误:

 Failed to execute goal on project test-xpath: Could not resolve dependencies for project com.kkk:test-xpath:jar:0.0.1-SNAPSHOT: Failure to find javax.xml:jaxrpc-api:jar:2.0_EA1 in https://mvnrepository.com/artifact/javax.xml/jaxrpc-api was cached in the local repository, resolution will not be reattempted until the update interval of repo1 has elapsed or updates are forced -> [Help 1]

UPD2

我了解到应该将spring存储库添加到我的依赖项中:

    <repositories>
    <repository>
      <id>repo1</id>
      <name>Repo 1</name>
      <url>http://repo.spring.io/plugins-release/</url>
    </repository>
  </repositories> 

我已删除.m2\repository\javax,并做了maven clean

maven compile产生错误:

Downloading from repo1: http://repo.spring.io/plugins-release/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.pom
Downloaded from repo1: http://repo.spring.io/plugins-release/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.pom (395 B at 736 B/s)
Downloading from repo1: http://repo.spring.io/plugins-release/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.jar
Downloading from central: https://repo.maven.apache.org/maven2/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.767 s
[INFO] Finished at: 2018-11-07T14:17:38+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test-xpath: Could not resolve dependencies for project com.kkk:test-xpath:jar:0.0.1-SNAPSHOT: Could not find artifact javax.xml:jaxrpc-api:jar:2.0_EA1 in repo1 (http://repo.spring.io/plugins-release/), try downloading from https://jax-rpc.dev.java.net/jaxrpc20-ea/ -> [Help 1]

如果我在pom.xml中没有<repository>的情况下执行了相同的操作,并且执行了maven compile,则我有相同的错误,但是它尝试从maven.repo下载pom。

Downloading from central: https://repo.maven.apache.org/maven2/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.pom (395 B at 987 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/javax/xml/jaxrpc-api/2.0_EA1/jaxrpc-api-2.0_EA1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.180 s
[INFO] Finished at: 2018-11-07T14:31:44+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test-xpath: Could not resolve dependencies for project com.kpv:test-xpath:jar:0.0.1-SNAPSHOT: Could not find artifact javax.xml:jaxrpc-api:jar:2.0_EA1 in central (https://repo.maven.apache.org/maven2), try downloading from https://jax-rpc.dev.java.net/jaxrpc20-ea/ -> [Help 1]

3 个答案:

答案 0 :(得分:0)

这不是正确使用存储库标记的方法。如果转到https://mvnrepository.com主页,您会看到它从多个存储库(例如中央存储库,jcenter存储库等)建立索引。因此,您必须使用标准存储库。

答案 1 :(得分:0)

如果打开maven repository页面,我们可以看到两个标签:中央插件和Spring插件。打开Spring插件标签,并尝试使用它,因为该版本是最新的,并且日期为2018年4月。

<!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api -->
<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>2.0_ea1</version>
</dependency>

另外,运行mvn clean命令,并确保删除javax位置的.m2文件夹。

答案 2 :(得分:0)

2.0_EA1在Maven Central上不存在。如果您使用1.1,您将看到它有效。非规范化semver版本似乎与非官方版本有关,可能是alpha版本。 在search.maven.org上的搜索声称它存在,但jar本身不存在

要检查工作版本,请执行以下操作:

<dependencies>
  <dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>1.1</version>
  </dependency>
</dependencies>

还请注意:错误Maven显示会告诉您,您可以从URL(不是存储库)中手动下载jar。

要仅回答问题的标题,您可以将存储库添加到pom.xml中,但是不需要添加中央Maven存储库,因此,我为您提供另一个存储库的示例:

<repositories>
    <repository>
        <id>jitpack</id>
        <name>jitpack</name>
        <url>https://jitpack.io</url>
    </repository>
</repositories>