如何解决maven中的依赖问题
How to struggle dependencies problems in maven
我遇到了 maven-jetty-plugin 的错误。我认为这个问题的发生是因为插件的传输依赖性,它与新库冲突。在我将 jersey1 更改为 jersey2 并将服务器 client/core/rs-ws 等的所有依赖项从 com.sun 更改为 org.glassfish 之后出现此错误
[ERROR] Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2:run
(default-cli) on project Plentify: Execution default-cli of goal org.eclipse.je
tty:jetty-maven-plugin:9.3.0.M2:run failed: An API incompatibility was encounter
ed while executing org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2:run: java.lang.
NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/stepan/.m2/repository/org/eclipse/jetty/jetty-m
aven-plugin/9.3.0.M2/jetty-maven-plugin-9.3.0.M2.jar
[ERROR] urls[1] = file:/C:/Users/stepan/.m2/repository/org/sonatype/sisu/sisu-in
ject-bean/2.1.1/sisu-inject-bean-2.1.1.jar
[ERROR] urls[2] = file:/C:/Users/stepan/.m2/repository/org/sonatype/sisu/sisu-gu
ice/2.9.4/sisu-guice-2.9.4-no_aop.jar
[ERROR] urls[3] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-utils/2.0.6/plexus-utils-2.0.6.jar
[ERROR] urls[4] = file:/C:/Users/stepan/.m2/repository/org/sonatype/aether/aethe
r-util/1.11/aether-util-1.11.jar
[ERROR] urls[5] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[6] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[7] = file:/C:/Users/stepan/.m2/repository/org/sonatype/plexus/plexu
s-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[8] = file:/C:/Users/stepan/.m2/repository/org/sonatype/plexus/plexu
s-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[9] = file:/C:/Users/stepan/.m2/repository/org/apache/maven/plugin-t
ools/maven-plugin-tools-api/3.1/maven-plugin-tools-api-3.1.jar
[ERROR] urls[10] = file:/C:/Users/stepan/.m2/repository/backport-util-concurrent
/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[11] = file:/C:/Users/stepan/.m2/repository/org/eclipse/jetty/jetty-
util/9.3.0.M2/jetty-util-9.3.0.M2.jar
等等...
谁能解答一下如何避免这种错误?谢谢
更新 1:http://pastebin.com/ag2zdiSH link 到完整的 pom
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- JPA SQL Implementation -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0-RC1</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
<artifactId>commonj.sdo</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- JPA NoSQL Implementation -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.nosql</artifactId>
<version>2.6.0</version>
</dependency>
<!-- Http Requests core -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
<!-- Common input output operations -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Java Bean to JSON and vice versa implementation -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
<type>jar</type>
</dependency>
<!-- mysql driver JDBC implementation -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!-- mongo driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.0</version>
</dependency>
<!-- servlet container -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- xml json web components -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- Authorization -->
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.authzserver</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.resourceserver</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.common</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- Scheduler -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
<!-- Mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- Query -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<!-- Cache -->
<dependency>
<groupId>com.whalin</groupId>
<artifactId>Memcached-Java-Client</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
我建议您使用两种方法来解决此问题。
首先我不会使用插件的里程碑版本。我可能会选择发布版本或至少是候选发布版本。你可以试试最近的9.3.0.RC1
。
如果这不能解决您的问题,您可能想尝试手动更新 POM 中 javax.ws.rs-api
的依赖项。但是我觉得你会在球衣本身上遇到麻烦。无论如何,试一试不会有什么坏处。要找出正确的版本,只需在更新前使用 POM 上的依赖层次结构即可。
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>XXX</version>
</dependency>
切勿将 com.sun.jersey
(1.x) 依赖项与 org.glassfish.jersey
(2.x) 依赖项混合。他们不相容。您看到的错误是将它们混合在一起的结果。
基本 Jersey 功能真正需要的是
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.17</version>
</dependency>
您可以删除您拥有的所有其他(Jersey 依赖项)。对于 JSON (Jackson) 支持,请使用
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.17</version>
</dependency>
对于嵌入式 Jetty(注意到您的 pom 包装是 "jar")配置,请参阅 。 JacksonFeature
是配置 Jackson 对 JSON 的支持。
编辑
再次查看您的 pom。除了插件之外,我没有看到 Jetty 依赖项。也许您不是要 运行 嵌入式实例。对于 web.xml 配置,您可以将其用作启动
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
you.can.list.a.comma.separated,
list.of.packages.to.scan.for,
resources.and.providers
</param-value>
</init-param>
<!-- This doesn't really need to be included.
Just showing how to add manually. -->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.jackson.JacksonFeature
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
我觉得很奇怪的一件事是你的包装是 jar
。您确定它不应该是 war
(从您的 Jetty 插件配置看来,您正在 运行 网络应用程序)。
我遇到了 maven-jetty-plugin 的错误。我认为这个问题的发生是因为插件的传输依赖性,它与新库冲突。在我将 jersey1 更改为 jersey2 并将服务器 client/core/rs-ws 等的所有依赖项从 com.sun 更改为 org.glassfish 之后出现此错误
[ERROR] Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2:run
(default-cli) on project Plentify: Execution default-cli of goal org.eclipse.je
tty:jetty-maven-plugin:9.3.0.M2:run failed: An API incompatibility was encounter
ed while executing org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2:run: java.lang.
NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.eclipse.jetty:jetty-maven-plugin:9.3.0.M2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/stepan/.m2/repository/org/eclipse/jetty/jetty-m
aven-plugin/9.3.0.M2/jetty-maven-plugin-9.3.0.M2.jar
[ERROR] urls[1] = file:/C:/Users/stepan/.m2/repository/org/sonatype/sisu/sisu-in
ject-bean/2.1.1/sisu-inject-bean-2.1.1.jar
[ERROR] urls[2] = file:/C:/Users/stepan/.m2/repository/org/sonatype/sisu/sisu-gu
ice/2.9.4/sisu-guice-2.9.4-no_aop.jar
[ERROR] urls[3] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-utils/2.0.6/plexus-utils-2.0.6.jar
[ERROR] urls[4] = file:/C:/Users/stepan/.m2/repository/org/sonatype/aether/aethe
r-util/1.11/aether-util-1.11.jar
[ERROR] urls[5] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[6] = file:/C:/Users/stepan/.m2/repository/org/codehaus/plexus/plexu
s-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[7] = file:/C:/Users/stepan/.m2/repository/org/sonatype/plexus/plexu
s-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[8] = file:/C:/Users/stepan/.m2/repository/org/sonatype/plexus/plexu
s-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[9] = file:/C:/Users/stepan/.m2/repository/org/apache/maven/plugin-t
ools/maven-plugin-tools-api/3.1/maven-plugin-tools-api-3.1.jar
[ERROR] urls[10] = file:/C:/Users/stepan/.m2/repository/backport-util-concurrent
/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[11] = file:/C:/Users/stepan/.m2/repository/org/eclipse/jetty/jetty-
util/9.3.0.M2/jetty-util-9.3.0.M2.jar
等等...
谁能解答一下如何避免这种错误?谢谢
更新 1:http://pastebin.com/ag2zdiSH link 到完整的 pom
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- JPA SQL Implementation -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0-RC1</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
<artifactId>commonj.sdo</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- JPA NoSQL Implementation -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.nosql</artifactId>
<version>2.6.0</version>
</dependency>
<!-- Http Requests core -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
<!-- Common input output operations -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Java Bean to JSON and vice versa implementation -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
<type>jar</type>
</dependency>
<!-- mysql driver JDBC implementation -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!-- mongo driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.0</version>
</dependency>
<!-- servlet container -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- xml json web components -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- Authorization -->
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.authzserver</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.resourceserver</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.common</artifactId>
<version>${oltu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- Scheduler -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
<!-- Mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- Query -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<!-- Cache -->
<dependency>
<groupId>com.whalin</groupId>
<artifactId>Memcached-Java-Client</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
我建议您使用两种方法来解决此问题。
首先我不会使用插件的里程碑版本。我可能会选择发布版本或至少是候选发布版本。你可以试试最近的9.3.0.RC1
。
如果这不能解决您的问题,您可能想尝试手动更新 POM 中 javax.ws.rs-api
的依赖项。但是我觉得你会在球衣本身上遇到麻烦。无论如何,试一试不会有什么坏处。要找出正确的版本,只需在更新前使用 POM 上的依赖层次结构即可。
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>XXX</version>
</dependency>
切勿将 com.sun.jersey
(1.x) 依赖项与 org.glassfish.jersey
(2.x) 依赖项混合。他们不相容。您看到的错误是将它们混合在一起的结果。
基本 Jersey 功能真正需要的是
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.17</version>
</dependency>
您可以删除您拥有的所有其他(Jersey 依赖项)。对于 JSON (Jackson) 支持,请使用
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.17</version>
</dependency>
对于嵌入式 Jetty(注意到您的 pom 包装是 "jar")配置,请参阅 JacksonFeature
是配置 Jackson 对 JSON 的支持。
编辑
再次查看您的 pom。除了插件之外,我没有看到 Jetty 依赖项。也许您不是要 运行 嵌入式实例。对于 web.xml 配置,您可以将其用作启动
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
you.can.list.a.comma.separated,
list.of.packages.to.scan.for,
resources.and.providers
</param-value>
</init-param>
<!-- This doesn't really need to be included.
Just showing how to add manually. -->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.jackson.JacksonFeature
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
我觉得很奇怪的一件事是你的包装是 jar
。您确定它不应该是 war
(从您的 Jetty 插件配置看来,您正在 运行 网络应用程序)。