NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll



我正在开发一个基于Jersey的Java(1.8)动态Web应用程序,并使用Maven来定义依赖关系。我正在使用Tomcat 9在Eclipse Oxygen中工作。 我是Web应用程序开发和Maven的新手,所以我正在努力理解如何使事情工作。

当我运行应用程序时,它失败并显示如下所示的错误。 我读过几篇文章。 此错误显然是由于编译时环境和运行时环境不匹配造成的。

我尝试更改各种组件的版本,希望找到正确的组合,但没有成功。我也尝试删除 .m2/存储库并运行 Maven/Update 项目来刷新环境,但这没有帮助。 也许有更多经验的人可以在我的pom.xml文件中发现不兼容的根源。

java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:335)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:222)
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:60)
at com.simfinit.client.SimDcmClient.get(SimDcmClient.java:36)
at com.simfinit.client.SimDcmClientTest.testGetList(SimDcmClientTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

这是我的pom.xml文件:

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.simfinit.resources</groupId>
<artifactId>SimWebServiceDcm</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SimWebServiceDcm</name>
<build>
<finalName>SimWebServiceDcm</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey.version}</version>
</dependency>
<!--        <dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
-->
<dependency>
<groupId>com.simfinit</groupId>
<artifactId>SimService</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.simfinit</groupId>
<artifactId>SimCommunication</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.simfinit</groupId>
<artifactId>SimServiceDcm</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.simfinit</groupId>
<artifactId>SimBase</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.26</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

我尝试使用"mvn dependency:tree"来识别可能的冲突。 此命令返回错误:

[ERROR] No plugin found for prefix 'dependency' in the current project and in the plugin groups...

我阅读了帮助文章和其他建议删除 .m2/repository 文件夹并重复 mvn 命令的文章。 结果如下所示。这些错误是否表明我在 pom 文件中提供了不正确的版本号? 我想这些信息应该对我有帮助,但我不知道下一步应该是什么。 我的pom的内容来自其他文章,但可能只对某些版本有效。 我一直在添加和替换pom依赖项,而实际上不知道如何确定更改的兼容性。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.758 s
[INFO] Finished at: 2018-05-17T14:56:56-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'help' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:UsersKent.m2repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
E:GitRepositoriessimfiniclientSimWebServiceDcm>mvn help:active-profiles
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.26/jersey-bom-2.26.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not transfer artifact org.glassfish.jersey:jersey-bom:pom:2.26 from/to central (https://repo.maven.apache.org/maven2): Permission denied: connect @ line 31, column 16
[ERROR] 'dependencies.dependency.version' for org.glassfish.jersey.containers:jersey-container-servlet-core:jar is missing. @ line 47, column 15
[ERROR] 'dependencies.dependency.version' for org.glassfish.jersey.media:jersey-media-moxy:jar is missing. @ line 54, column 15
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.simfinit.resources:SimWebServiceDcm:1.0-SNAPSHOT (E:GitRepositoriessimfiniclientSimWebServiceDcmpom.xml) has 3 errors
[ERROR]     Non-resolvable import POM: Could not transfer artifact org.glassfish.jersey:jersey-bom:pom:2.26 from/to central (https://repo.maven.apache.org/maven2): Permission denied: connect @ line 31, column 16 -> [Help 2]
[ERROR]     'dependencies.dependency.version' for org.glassfish.jersey.containers:jersey-container-servlet-core:jar is missing. @ line 47, column 15
[ERROR]     'dependencies.dependency.version' for org.glassfish.jersey.media:jersey-media-moxy:jar is missing. @ line 54, column 15
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

此错误确实来自编译时和运行时依赖项版本之间的不匹配,但它可能并不完全在 maven 方面。

首先:做mvn dependency:tree并寻找jax-ws。如果您发现多个具有不同版本的版本:使用排除选项在pom中排除它们。

如果您没有找到任何内容或它没有帮助:检查您的 tomcat 安装和配置(像 libs 这样的文件夹,或者在启动期间是否添加了任何额外的 jar)。一旦我在使用 Guava 时遇到这样的问题,我使用的是 23.0,我的应用程序服务器使用的是 12.0,它优先于我的。

如果它无助于检查您的JDK和endorsed文件夹,也许您那里有额外的东西。

从未使用过最新版本的JavaEE和Tomcat,但也许通用解决方案会在这里有所帮助。

最新更新