问题描述
我正在尝试发动一场我没有写过的战争,并且我的日志中出现此错误:
I am trying to deploy a war that i didnt write and i am getting this error in my logs:
java.lang.NoClassDefFoundError: HttpSessionListener
我知道HttpSessionListener驻留在 servlet-api.jar 中,该文件位于tomcat(我的应用服务器)的lib目录中.
i know that HttpSessionListener lives in servlet-api.jar which is found in the lib dir of tomcat(my app server).
我尝试将servlet-api.jar包含在战争的WEB-INF/lib文件夹中,但这样做的日志对我大喊:
I tried including servlet-api.jar in the war's WEB-INF/lib folder, but the logs yelled at me for doing that:
INFO: validateJarFile(/home/test/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
互联网声称您不必在lib文件夹中包含该类.
the internets claim that you dont have to include that class in your lib folder.
修改:我从web.xml中删除了令人反感的侦听器(这是导致上述问题的原因),因为它看起来并不十分重要.这显示出更多错误:
edit:i removed the offending listener (which was causing the problem above) from web.xml because it didnt look very important. this revealed more errors:
java.lang.Error: Unresolved compilation problem:
The type javax.servlet.FilterChain cannot be resolved. It is indirectly referenced from required .class files
我想念什么?
推荐答案
@BalusC的解释听起来比我的解释更合理...
@BalusC's explanation sounds more plausible than mine ...
一些其他可能的解释/需要检查的东西:
Some other possible explanations / things to check:
-
servlet-api.jar不在$ CATALINA_HOME/lib中,或者由于某种原因不包含该类. (我知道您说过您知道"它在那儿,但您没有明确说您已检查过它.)
The servlet-api.jar is not in $CATALINA_HOME/lib, or for some reason doesn't contain the class. (I know you said you "know" it's there, but you didn't specifically say you checked it.)
其他问题已损坏,这导致在静态初始化期间首次尝试加载HttpSessionListener
失败并发生未捕获的异常. (因为HttpSessionListener
是一个接口,所以这有点难以置信.但是,为防万一,值得检查日志中是否有较早的类加载错误……)
Something else is broken which caused the first attempted load of HttpSessionListener
to fail with an uncaught exception during static initialization. (This is kind of implausible, since HttpSessionListener
is an interface. But it is worth checking the logs for earlier class loading errors ... just in case.)
缺少的类可能被命名为foo.bar.HttpSessionListener
,而不是javax.servlet.http.HttpSessionListener
.这可能会显示在嵌套堆栈跟踪中.
The missing class might be named foo.bar.HttpSessionListener
rather than javax.servlet.http.HttpSessionListener
. This is likely to show up in the nested stack trace.
如果您要部署的WAR中的某些内容正在创建自己的类加载器,则可能是这样做做错了,并且HttpSessionListener
类不在类加载器的有效类路径上.
If something in the WAR you are deploying is creating its own classloader, it is possible that is is doing this incorrectly and the HttpSessionListener
class is not on the classloader's effective classpath.
编辑
如果现在在日志中看到未解决的编译错误,则应该怀疑WAR文件及其生成过程.具体来说,听起来WAR包含具有Java编译错误的类!
If you are now seeing unresolved compilation errors reported in the logs, you should be suspecting the WAR file and the process used to build it. Specifically, it sounds like the WAR includes classes that had Java compilation errors!
(或者也许这是编译JSP的问题...但是也会在日志中显示.)
(Or maybe this is a problem compiling JSPs ... but that would show up in the logs too.)
这篇关于java.lang.NoClassDefFoundError:HttpSessionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!