我正在开发基于Jersey的Java(1.8)动态Web应用程序,并使用Maven定义依赖项。我正在使用Tomcat 9在Eclipse Oxygen中工作。我是Web应用程序开发和Maven的新手,因此我很难理解如何使工作正常。
当我运行应用程序时,它失败并显示如下所示的错误。我看过几篇文章。此错误显然是由于编译时环境与运行时环境不匹配造成的。
我尝试更改各种组件的版本,希望找到合适的组合,但没有成功。我也尝试删除.m2 / repository并运行Maven / Update Project来刷新环境,但这没有帮助。也许具有更多经验的人可以在我的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:\Users\Kent\.m2\repository), 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:\GitRepositories\simfiniclient\SimWebServiceDcm>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:\GitRepositories\simfiniclient\SimWebServiceDcm\pom.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
答案 0 :(得分:1)
这个错误确实来自编译时和运行时依赖版本之间的不匹配,但它可能不完全在maven方面。
首先:做mvn dependency:tree
并寻找jax-ws。如果您发现具有不同版本的多个版本:使用exclude option将其排除在pom中。
如果您没有找到任何内容或它没有帮助:检查您的tomcat安装和配置(文件夹如libs或在启动时添加任何额外的jar)。一旦我遇到Guava这样的问题,我使用的是23.0,我的app-server使用的是12.0,它优先于我的。
如果它无法检查您的JDK和endorsed
文件夹,那么您可能还有其他内容。
从未使用过最新版本的JavaEE和Tomcat,但通常的解决方案可能会对此有所帮助。