Tomcat 7.0.29 servlet-api类加载器问题

avh*_*vhv 5 java tomcat servlets classloader

我目前正在尝试将我们的构建从手动过程(MyEclipse/export as war)更改为自动Maven Build.

由MyEclipse构建的war应用程序在我们的Tomcat 7.0.29安装(Windows 7)上部署并运行正常.在MyEclipse构建路径中,我们配置了一个用户库(tomcat),其中包含来自的所有jar $CATALINA_HOME/lib.

我们有一些使用javax.servlet.http.*classes(HttpSessionEvent等)的servlet监听器和过滤器.它们是打包的WEB-INF\classes\com\mycompany\filters

在部署由Maven构建的战争时,我NoClassDefFoundError上了HttpSessionEvent课.我用-verbose:class JVM选项进行了跟踪,我看到最后加载的类是我的c:\apache\webapps\myapp\WEB-INF\classes\com\mycompany\filters目录过滤器 .然后我尝试加载/查找HttpSessionEvent并且无法执行此操作.

servlet-api.jar当然是在我的$CATALINA_HOME\lib目录中.

在我的pom.xml中,我有这种依赖

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.29</version>
        <scope>provided</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我的路径/类路径中的任何地方都没有其他servlet-api.jar文件(双重检查我的jdk和jre的lib/ext和endorsed目录)

我的maven依赖:树看起来像这样:

[INFO] +- log4j:log4j:jar:1.2.15:compile
[INFO] |  \- javax.mail:mail:jar:1.4:compile
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.jdom:jdom:jar:1.1:provided
[INFO] +- com.sun.xml.rpc:jaxrpc-impl:jar:1.1.3_01:provided
[INFO] |  +- javax.xml:jaxrpc-api:jar:1.1:provided
[INFO] |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3:provided
[INFO] |  |  \- javax.xml.soap:saaj-api:jar:1.3:provided
[INFO] |  +- com.sun.xml.rpc:jaxrpc-spi:jar:1.1.3_01:provided
[INFO] |  \- com.sun.xml.fastinfoset:FastInfoset:jar:1.0.2:provided
[INFO] +- org.apache.lucene:lucene-core:jar:3.6.0:compile
[INFO] +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.1.0.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-orm:jar:3.1.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:3.1.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:3.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:3.1.0.RELEASE:test
[INFO] +- org.aspectj:aspectjrt:jar:1.7.1:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.7.1:compile
[INFO] +- javax.faces:javax.faces-api:jar:2.1:compile
[INFO] +- com.sun.faces:jsf-impl:jar:2.1.15:compile
[INFO] +- org.primefaces:primefaces:jar:3.4.2:compile
[INFO] +- org.richfaces.core:richfaces-core-api:jar:4.2.3.Final:compile
[INFO] |  \- com.google.guava:guava:jar:11.0.2:compile
[INFO] |     \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- org.richfaces.ui:richfaces-components-ui:jar:4.2.3.Final:compile
[INFO] |  \- org.richfaces.ui:richfaces-components-api:jar:4.2.3.Final:compile
[INFO] +- org.apache.tomcat:tomcat-servlet-api:jar:7.0.29:provided
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.2:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.2:compile
[INFO] +- org.hibernate:hibernate-core:jar:3.6.2.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] |  \- javax.transaction:jta:jar:1.1:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.6.2.Final:compile
[INFO] |  +- cglib:cglib:jar:2.2:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile
[INFO] |  \- javassist:javassist:jar:3.12.0.GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.1.0.Final:compile
[INFO] |  \- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.apache.commons:commons-email:jar:1.2:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- com.h2database:h2:jar:1.3.170:test
Run Code Online (Sandbox Code Playgroud)

我一直在互联网上搜索这个问题,从我读过的内容来看,这必须与tomcat类加载器有关.很可能我的战争包装出了问题.但是,我还没有找到解决方案.

任何指针将非常感谢!

Ton*_*per 0

您是否检查过WEB-INF/lib构建的 .war 并绝对确定servlet-api.jar不存在?据我所知,Maven 依赖项具有正确的范围。

buildpom.xml 中的部分应与此类似:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <warName>war_name</warName>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

不,不要放入servlet-api.jar您的网络应用程序的WEB-INF/lib文件夹中。另外,我认为你不需要 tomcat 用户库。您唯一需要的库是JRE System Library xxMaven Dependencies