以下工件无法解析:javax.jms:jms:jar:1.1

81

我正在尝试编译一个Maven项目,但我始终收到以下错误信息:

[ERROR]Failed to execute goal on project ...:
Could not resolve dependencies for project ...:war:1.0.0:
The following artifacts could not be resolved: javax.jms:jms:jar:1.1,
com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1:
Failure to find javax.jms:jms:jar:1.1 in http://mirrors.ibiblio.org/maven2/
  was cached in the local repository, resolution will not be reattempted until
  the update interval of maven2-repository.ibiblio.mirror has elapsed or
  updates are forced -> [Help 1]

我了解这篇关于Sun jars的Maven文章,但它并没有解决问题。

我能在我的pom.xml中指定一个仓库吗?

10个回答

86

感谢您的建议。在阅读这篇文章后,我终于找到了解决这个问题的方法。原来这些依赖项都是来自对ZooKeeper的依赖。

我修改了我的pom.xml文件如下,问题得以解决:

    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
        <version>3.3.2</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

2
好的解决方法。我今天遇到了与log4j依赖项相同的问题。看起来https://maven-repository.dev.java.net/nonav/repository可能有一个无效的证书(当我访问该网址时,Chrome会给我一个大警告)。我想那是这些依赖项托管的服务器。 - James Cooper
我也收到了SSL证书警告,但后来意识到这是因为该域名不存在。这是由于OpenDNS和他们的默认回退页面引起的。 - Steve Buzonas
5
看起来短暂依赖项log4j:log4j:1.2.15正在引入这些奇怪的依赖项。从zookeeper依赖项中排除log4j,并自行包含更新版本的log4j也能解决这个问题。 - JeroenHoek
1
@JamesCooper 请查看此链接(http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/)。它解释了log4j的问题。 - smwikipedia

67
如果任何人仍然想使用jms1.1,则添加公共的jboss存储库,maven会找到它...
项目->依赖项:
  <dependencies>
    <dependency>
      <groupId>javax.jms</groupId>
      <artifactId>jms</artifactId>
      <version>1.1</version>
    </dependency>

项目->仓库:

  <repositories>
    <repository>
      <id>repository.jboss.org-public</id>
      <name>JBoss.org Maven repository</name>
      <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>  

它可以工作 -

F:\mvn-repo-stuff>mvn verify
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mvn-repo-stuff 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.pom
Downloaded: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.pom (677 B at 0.8 KB/sec)
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
Downloading: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
Downloading: https://repository.jboss.org/nexus/content/groups/public/javax/jms/jms/1.1/jms-1.1.jar
Downloaded: https://repository.jboss.org/nexus/content/groups/public/javax/jms/jms/1.1/jms-1.1.jar (26 KB at 8.5 KB/sec)

我只在这个仓库里找到了它: https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/ - krakover
你把它放在<repositories>部分了吗?但这对我的情况没有帮助。 - haridsv
我将存储库放置在用户设置settings.xml中,但对我来说它也没有起作用。 - despot
对我来说,它一直报错。在java.net中找不到artifact org.jboss.com.sun.httpserver:httpserver:jar:1.0.0.Final。当我将存储库更改为jboss时,现在已下载..谢谢。 - Dhrumil Shah

24

Log4版本1.2.17自动解决了此问题,因为它依赖于geronimo-jms。我在log4j-1.2.15版本中遇到了相同的问题。


进一步了解该问题


使用1.2.17版本可以在编译时解决问题,但是服务器(Karaf)在运行时使用的是1.2.15版本,因此会产生冲突。因此,我不得不切换回1.2.15版本。

JMS和JMX API在运行时对我可用,因此我没有导入J2ee API。

我的做法是在编译时依赖1.2.17版本,但在运行时删除它。

            <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
....
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                                                          <Import-Package>!org.apache.log4j.*,*</Import-Package>

.....

15

如果您不想修改您的设置,另一个解决方案是:

从 JBoss 存储库下载 jms-1.1.jar,然后执行以下命令:

mvn install:install-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar -Dfile=jms-1.1.jar


它一直工作到编译项目。谢谢。一个问题:如果我删除了 .m2 文件夹,我需要再次发出这个命令。我是对的吗? - hephestos
如果我删除了 .m2 文件夹,我需要再次发出这个命令吗?<< 是的,你需要。mvn install 将会把一个构件复制到你本地的 mvn 仓库。 - Adrián Deccico

4

我认为如果你的项目依赖于JMS,这是最好的解决方案。这样你就可以将JMS的解析委托给Maven,正如人们理想地期望的那样。 - danidemi
简单易行的解决方案。无需添加新的存储库。 - downeyt

3
尝试使用mvn的cpu选项强制更新:
usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -cpu,--check-plugin-updates            Force upToDate check for any
                                        relevant registered plugins

不建议使用-cpu。原因是:“命令行选项-cpu已被弃用,并将在未来的Maven版本中删除。” - despot

3

在我的项目中使用log4j(1.2.15)的maven依赖版本时,我也遇到了同样的问题。

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
</dependency>

我遇到了以下错误:

The following artifacts could not be resolved: javax.jms:jms:jar:1.1, com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Could not transfer artifact javax.jms:jms:jar:1.1 from/to java.net (https://maven-repository.dev.java.net/nonav/repository): Cannot access https://maven-repository.dev.java.net/nonav/repository with type legacy using the available connector factories: BasicRepositoryConnectorFactory: Cannot access https://maven-repository.dev.java.net/nonav/repository with type legacy using the available layout factories: Maven2RepositoryLayoutFactory: Unsupported repository layout legacy -> [Help 1]

我开始使用以下log4j(1.2.17)版本,并且它帮助我解决了这个问题,而无需进行任何相关的配置修复。

 <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

2

检查 iblibliojava.net 库发现都没有与jmx相关的jar文件。我认为您应该按照这里所讨论的方法手动下载并本地安装jms。


我同意。这解决了大部分的问题。浏览jarvana.com网站,并在Project字段中输入你所寻找的jar的groupId和artifactId。如果你找不到这个文件,那就检查一下pom文件,试图找出从哪里可以下载它(在此处查看downloadUrl:http://jarvana.com/jarvana/inspect-pom/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.pom)。下载后,请使用以下命令:mvn install:install-file -DgroupId=groupIdOfJar -DartifactId=artifactIdOfJar -Dversion=versionOfJar -Dpackaging=jar -Dfile="pathToJar.jar" -DgeneratePom=true - despot
还可以在这里检查不同的存储库:http://docs.codehaus.org/display/MAVENUSER/Mirrors+Repositories 以及Maven的镜像和存储库指南:http://maven.apache.org/guides/mini/guide-mirror-settings.html - despot

0

可能不是完全相同的问题,但有一篇关于相同主题的好文章 在这里


最好总结文章,以防链接失效。 - cosbor11

0

你导入了一个依赖项,而这个依赖项又依赖于com.sun.jmx:jmxri:jar:1.2.1和其他的依赖项,但是com.sun.jmx:jmxri:jar:1.2.1在中央仓库中找不到,

所以最好尝试导入另一个版本。

假设你的依赖项可能是log4j,你可以尝试导入log4j:log4j:jar:1.2.13


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接