我有一个使用EJB 3,JPA,JAX-RS和CDI的Java EE应用程序。我包含了jetty maven插件,并希望指定实现jetty中缺少的API的依赖项。我使用了以下依赖项列表和jetty配置。
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.3.v20150827</version>
<configuration>
<jettyXml>src/test/resources/jetty.xml</jettyXml>
</configuration>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.2</version>
</dependency>
</dependencies>
</plugin>
然后我的jetty.xml配置就是这个
<Configure id ="h2" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="h2Datasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/h2</Arg>
<Arg>
<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
<Set name="driverClass">org.h2.Driver</Set>
<Set name="jdbcUrl">jdbc:h2:./target/db/testdb</Set>
<Set name="user">sa</Set>
<Set name="password"></Set>
</New>
</Arg>
</New>
</Configure>
但是当我做mvn clean package jetty时:运行我得到这个例外:
[ERROR] Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.3.3.v20150827:run (default-cli) on project dip-cv-web: Execution default-cli of goal org.eclipse.jetty:jetty-maven-plugin:9.3.3.v20150827:run failed: An API incompatibility was encountered while executing org.eclipse.jetty:jetty-maven-plugin:9.3.3.v20150827:run: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
如果需要,我可以提供更多详细信息。不确定您可能会发现还有什么帮助我调试此问题。
谢谢!
答案 0 :(得分:0)
当您在类路径上有两个不同版本的类时,通常会得到“NoSuchMethodError”。 由于javax.ws.rs.core.Application类在其JAX-RS 2版本中具有getProperties()方法,但在JAX-RS 1.x中没有。
您可以使用以下maven命令获取依赖关系树
mvn dependency:tree -Dverbose -Dincludes=javax.ws.rs
--- maven-dependency-plugin:2.8:tree (default-cli) @ language-processing ---
- +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.23.2:compile
- | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.23.2:com
- | | \- (javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile - omitted for duplicate)
- | +- org.glassfish.jersey.core:jersey-common:jar:2.23.2:compile
- | | \- (javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile - omitted for duplicate)
- | +- org.glassfish.jersey.core:jersey-server:jar:2.23.2:compile
- | | +- org.glassfish.jersey.core:jersey-client:jar:2.23.2:compile
- | | | \- (javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile - omitted for duplicate
- | | \- (javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile - omitted for duplicate)
- | \- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
- \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.23.2:compile
- \- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.23.2:compile
- \- (javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile - omitted for duplicate)
您的jersey-container-servlet
依赖项会带来javax.ws.rs-api-2.0.1.jar