我正在尝试部署我没有编写的 war ,但我在日志中收到此错误:
java.lang.NoClassDefFoundError: HttpSessionListener
我知道 HttpSessionListener 存在于 servlet-api.jar 中,它位于 tomcat(我的应用服务器)的 lib 目录中。
我尝试将 servlet-api.jar 包含在 war 的 WEB-INF/lib 文件夹中,但日志对我大喊大叫:
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 文件夹中。
编辑: 我从 web.xml 中删除了有问题的监听器(这是导致上述问题的原因),因为它看起来不是很重要。这揭示了更多错误:
java.lang.Error: Unresolved compilation problem:
The type javax.servlet.FilterChain cannot be resolved. It is indirectly referenced from required .class files
我错过了什么?
最佳答案
虽然这个问题太老了,但现在会讲述一个可能的问题。根据 Tomcat 10 download page :
Users of Tomcat 10 onwards should be aware that, ..., the primary package for all implemented APIs has changed from
javax.*
tojakarta.*
. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
所以使用 Tomcat 9 而不是 10。
关于java.lang.NoClassDefFoundError : HttpSessionListener 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3902705/