0

我正在尝试使用 JAX RS 服务。我在我的 pom .xml 中添加了一些依赖项。这是pom。

    <properties>
    <jersey.version>1.19</jersey.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.version}</version>
    </dependency>


    <dependency>
        <groupId>org.mvel</groupId>
        <artifactId>mvel2</artifactId>
        <version>2.2.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.drill.exec</groupId>
        <artifactId>drill-jdbc-all</artifactId>
        <version>1.1.0</version>
    </dependency>

</dependencies>

当我添加此依赖项时<dependency> <groupId>org.apache.drill.exec</groupId> <artifactId>drill-jdbc-all</artifactId> <version>1.1.0</version> </dependency> ,它会因以下提到的异常而失败。我需要上面提到的 apache 演习的依赖。在删除和运行它工作顺利。

我得到的例外是:

java.lang.NoSuchMethodError: org.codehaus.jackson.map.AnnotationIntrospector.pair(Lorg/codehaus/jackson/map/AnnotationIn
trospector;Lorg/codehaus/jackson/map/AnnotationIntrospector;)Lorg/codehaus/jackson/map/AnnotationIntrospector;
    at org.codehaus.jackson.jaxrs.MapperConfigurator._resolveIntrospectors(MapperConfigurator.java:155)
    at org.codehaus.jackson.jaxrs.MapperConfigurator._setAnnotations(MapperConfigurator.java:133)
    at org.codehaus.jackson.jaxrs.MapperConfigurator.getDefaultMapper(MapperConfigurator.java:70)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.locateMapper(JacksonJsonProvider.java:648)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:500)
    at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.writeTo(JacksonProviderProxy.java:160)
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291).

有人可以帮忙解释一下为什么在添加特定依赖项时它会因上述异常而失败。

尝试运行 mvn 依赖树来检查 jar 中的冲突。


构建 JAXRS-JSON Maven Webapp 0.0.1-SNAPSHOT

------------------------------------------------------------------------

 --- maven-dependency-plugin:2.8:tree (default-cli) @ JAXRS-JSON ---
 com.java.codegeeks.example:JAXRS-JSON:war:0.0.1-SNAPSHOT
 +- com.sun.jersey:jersey-servlet:jar:1.19:compile
 |  \- com.sun.jersey:jersey-server:jar:1.19:compile
 +- com.sun.jersey:jersey-json:jar:1.19:compile
 |  +- org.codehaus.jettison:jettison:jar:1.1:compile
 |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
 |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
 |  |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
 |  |     \- javax.activation:activation:jar:1.1:compile
 |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
 |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
 |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.2:compile
 |  +- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
 |  \- com.sun.jersey:jersey-core:jar:1.19:compile
 |     \- javax.ws.rs:jsr311-api:jar:1.1.1:compile
 +- com.sun.jersey:jersey-client:jar:1.19:compile
 +- junit:junit:jar:3.8.1:test
 \- org.apache.drill.exec:drill-jdbc-all:jar:1.1.0:compile
 ------------------------------------------------------------------------
 BUILD SUCCESS
4

1 回答 1

0

钻里面包含太多的包,它与应用程序中的其他 jar 冲突。我也遇到了类似的问题,但是使用了钻 jar 的 com.google.common.collect 和 org.apache.zookeeper 包。在我的情况下,用于这些包的版本钻比较旧,所以我只是删除了这些。

zip -d drill-jdbc-all-1.1.0.jar com/google/common/collect/*
zip -d drill-jdbc-all-1.1.0.jar org/apache/zookeeper/*

现在它工作正常。我不确定如何仅使用 maven 处理所有这些,因此选择删除。如果maven能处理这个会更好。

于 2015-10-12T07:15:22.243 回答