servlet-api.jar not loaded

本文介绍了如何解决Tomcat启动时因servlet-api.jar包冲突导致的问题,通过移除项目中多余的包或将Tomcat库中的servlet-api.jar包复制到java安装目录下的ext文件夹来解决冲突,避免了源程序无法编译的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

启动tomcat后,控制台输出信息:WEB-INF/lib/servlet-api.jar not loaded. See Servlet Spec 2.3, section 9.7.2。网上提供的方法一般是:保证WEB-INF/lib跟tomcat6.0 lib下的JAR包与项目的web-inf/lib没有重复的包即可。所以,将项目的web-inf/lib下的servlet-api.jar删掉就OK了。

但是,如果项目中存在使用servlet-api.jar的类怎么办呢?删掉servlet-api.jar,源程序无法编译。这时,有另一个办法可以解决这样的冲突问题:把Tomcat6.0t的lib目录下的名为servlet-api.jar的包拷贝至你的java安装目录下jre/lib/ext下就可以了。在myeclipse7.0中再次启动tomcat6.0就不会再出现前面的输出信息了。


<really ?! >

其实,对于两者的包冲突问题,都可以采用类似的方法来解决。

<really ?! >


经过自己的证实,上面的解决方案不成功,


另外:

 

把 webapps\maintenance\WEB-INF\lib\
下面的 servlet-api.jar 删掉吧! tomcat自己有,不需要你提供!
顺便看看其他的jar, 和 tomcat\lib 目录比较一下,tomcat已经有的,就别留着了!

 

这才想起,我在tomcat/common/lib/中也放入了j2ee.jar等包,去common/lib中处不必要的包后,保证tomcat/common/lib/和WEB-INF/lib这两个目录下的jar没有重复的,问题解决。
原来,tomcat 启动后先将tomcat/common/lib目录下的jar包全部读入内存,如果webapps目录里的应用程序中WEB-INF/lib目录下有相同的包,将无法加载,估计不同版本的包之间也会造成类似问题。因此建议尽量不要把jar包放入tomcat/common/lib目录下,应该放入WEB- INF/lib目录下。

An attempt was made to call a method that does not exist. The attempt was made from the following location: org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1200) The following method did not exist: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; The calling method's class, org.apache.catalina.authenticator.AuthenticatorBase, was loaded from the following location: jar:file:/D:/Maven/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.96/tomcat-embed-core-9.0.96.jar!/org/apache/catalina/authenticator/AuthenticatorBase.class The called method's class, javax.servlet.ServletContext, is available from the following locations: jar:file:/D:/Maven/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/D:/Maven/repository/javax/servlet/javax.servlet-api/4.0.1/javax.servlet-api-4.0.1.jar!/javax/servlet/ServletContext.class jar:file:/D:/Maven/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.96/tomcat-embed-core-9.0.96.jar!/javax/servlet/ServletContext.class The called method's class hierarchy was loaded from the following locations: javax.servlet.ServletContext: file:/D:/Maven/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes org.apache.catalina.authenticator.AuthenticatorBase and javax.servlet.ServletContext 16:23:59.301 [Thread-15] WARN c.a.n.c.n.NotifyCenter - [shutdown,136] - [NotifyCenter] Start destroying Publisher 16:23:59.301 [Thread-10] WARN c.a.n.c.h.HttpClientBeanHolder - [shutdown,102] - [HttpClientBeanHolder] Start destroying common HttpClient 16:23:59.301 [Thread-15] WARN c.a.n.c.n.NotifyCenter - [shutdown,153] - [NotifyCenter] Destruction of the end
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值