不同的servlet-api版本冲突 [英] Different servlet-api versions collision

查看:211
本文介绍了不同的servlet-api版本冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven和Jetty作为服务器来开发RestEasy Web服务.服务之一应使用扩展javax.servlet.http.HttpServletResponseWrapper的Filter.问题出在来自servlet-api 2.3的接口javax.servlet.ServletResponse的方法setCharacterEncoding中.我收到以下异常

I'm developing RestEasy web services using Maven and Jetty as the server. One of the services should use Filter that extends javax.servlet.http.HttpServletResponseWrapper. The problem is in method setCharacterEncoding of the interface javax.servlet.ServletResponse which comes from servlet-api 2.3. I'm getting the following exception

java.lang.NoSuchMethodError: com.webapp.rest.jsonp.HttpServletResponseContentWrapper.setCharacterEncoding(Ljava/lang/String;)V

我像这样自定义了servlet-api 2.4依赖关系,但也尝试使用2.5:

I've speficied servlet-api 2.4 dependency as this, but also tried with 2.5:

 <web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

Servlet-api 2.4的指定如下:

Servlet-api 2.4 is specified like this:

 <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
    <scope>provided</scope>
 </dependency>

我正在使用Maven码头插件:

I'm using Maven jetty plugin:

 <plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.15</version>
<configuration>
 ....
 <exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>

我的RestEasy配置:

My RestEasy configuration:

 <dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jettison-provider</artifactId>
<version>2.2.2.GA</version>
<exclusions>
    <exclusion>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    </exclusion>

但是,在Maven资源库中,总是有2.3和2.4(或2.5)版本.我不知道这个2.3版本是否带有其他依赖项.有什么建议我该如何找出以及如何执行要使用的servlet-api 2.4.

However, in maven repository there are always both 2.3 and 2.4 (or 2.5) versions. I can't figure out if this 2.3 version comes with some other dependency. Is there any suggestion how could I find out this and how to enforce servlet-api 2.4 to be used.

我的依赖树如下:

[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.inextweb.ai:inextweb-ai:war:1.0.0-SNAPSHOT
[INFO] +- org.htmlparser:htmlparser:jar:2.1:compile
[INFO] +- org.htmlparser:htmllexer:jar:2.1:compile
[INFO] +- org.htmlparser:thumbelina:jar:2.1:compile
[INFO] +- org.htmlparser:sitecapturer:jar:2.1:compile
[INFO] +- org.htmlparser:filterbuilder:jar:2.1:compile
[INFO] +- net.sf.jung:jung-api:jar:2.0.1:compile
[INFO] |  \- net.sourceforge.collections:collections-generic:jar:4.01:compile
[INFO] +- net.sf.jung:jung-algorithms:jar:2.0.1:compile
[INFO] |  \- colt:colt:jar:1.2.0:compile
[INFO] |     \- concurrent:concurrent:jar:1.3.4:compile
[INFO] +- net.sf.jung:jung-graph-impl:jar:2.0.1:compile
[INFO] +- net.sf.jung:jung-visualization:jar:2.0.1:compile
[INFO] +- org.apache.opennlp:opennlp-tools:jar:1.5.2-incubating:compile
[INFO] |  +- org.apache.opennlp:opennlp-maxent:jar:3.0.2-incubating:compile
[INFO] |  \- jwnl:jwnl:jar:1.3.3:compile
[INFO] +- net.sf.jwordnet:jwnl:jar:1.4_rc3:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.testng:testng:jar:6.1.1:test
[INFO] |  +- org.beanshell:bsh:jar:2.0b4:test
[INFO] |  +- com.beust:jcommander:jar:1.12:test
[INFO] |  \- org.yaml:snakeyaml:jar:1.6:test
[INFO] +- commons-pool:commons-pool:jar:1.6:compile
[INFO] +- commons-codec:commons-codec:jar:1.7:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.10.1:compile
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:2.3.5.Final:compile
[INFO] |  +- org.jboss.resteasy:jaxrs-api:jar:2.3.5.Final:compile
[INFO] |  +- org.scannotation:scannotation:jar:1.0.3:compile
[INFO] |  |  \- javassist:javassist:jar:3.12.1.GA:compile
[INFO] |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |  +- javax.activation:activation:jar:1.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] |  \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-jackson-provider:jar:2.2.2.GA:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.6.3:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.6.3:compile
[INFO] |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.6.3:compile
[INFO] |  \- org.codehaus.jackson:jackson-xc:jar:1.6.3:compile
[INFO] +- org.jboss.resteasy:resteasy-jettison-provider:jar:2.2.2.GA:compile
[INFO] |  +- org.jboss.resteasy:resteasy-jaxb-provider:jar:2.2.2.GA:compile
[INFO] |  |  \- com.sun.xml.stream:sjsxp:jar:1.0.1:compile
[INFO] |  \- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] +- org.simpleframework:simple-xml:jar:2.3.6:compile
[INFO] |  +- stax:stax-api:jar:1.0.1:compile
[INFO] |  \- stax:stax:jar:1.2.0:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- com.google.code.gson:gson:jar:2.2.2:system
[INFO] +- junit:junit:jar:3.8.2:compile
[INFO] +- xalan:serializer:jar:2.7.1:compile
[INFO] +- bouncycastle:bcprov-jdk15:jar:140:compile
[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- xom:xom:jar:1.1:compile
[INFO] |  +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] |  +- xerces:xercesImpl:jar:2.6.2:compile
[INFO] |  +- xalan:xalan:jar:2.7.0:compile
[INFO] |  \- jaxen:jaxen:jar:1.1-beta-8:compile
[INFO] |     \- jdom:jdom:jar:1.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.6:compile
[INFO] +- org.slf4j:jul-to-slf4j:jar:1.6.6:compile
[INFO] \- org.slf4j:jcl-over-slf4j:jar:1.6.6:runtime
[INFO] ------------------------------------------------------------------------

这是整个 pom.xml 谢谢

推荐答案

我发现这里是什么问题.在maven-jetty-plugin中,我添加了commons-logging的依赖关系,每次我运行jetty时,它都会拉取servlet-api 2.3.一旦我删除了这种依赖关系,一切就很好了.

I found what is the problem here. In maven-jetty-plugin I added dependency for commons-logging which pulled servlet-api 2.3 each time I run jetty. Once I removed this dependency, everything was fine.

感谢您的帮助.

这篇关于不同的servlet-api版本冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆