关于eclipse+tomcat调试时,Servlet Jar not Loaded的问题
来源:互联网 发布:著名的网络炒作事件 编辑:程序博客网 时间:2024/05/16 14:10
转载自:http://stackoverflow.com/questions/1993493/error-servlet-jar-not-loaded
运行时,报错信息如下:
INFO: validateJarFile(C:\dev\server\tomcat6\webapps Sempedia\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, sectoin 9.7.2. Offending class: javax/servlet/Servlet.class
原因如下:
大致就是说,tomcat的lib下有servlet的jar包了,你项目里面依赖的servlet jar包不会被加载
The first error message you got was because Tomcat doesn't need to load the servlet jar because italready has one and wants to avoid conflicts.
You can usually safely ignore the warning. If you don't want it to appear, you need to move the servlet jar from your project, rather than using the one from tomcat. By taking the tomcat one and putting it into your project, you've managed to convince tomcat to load it from your webapp rather than from from where it was expecting it, causing a classloader issue as mentioned in the BalusC's answer.
Edit: The above was edited to clarify what was happening once you put the servlet-api jar from tomcat into your webapp (and attribute BalusC).
一些解决方案:
This is a sign of classpath pollution. The JSP/Servlet API libraries are appserver implementation dependent and belongs in case of Tomcat 6 in theTomcat/lib
folder and should inno way be moved nor duplicated somewhere else. It's recipe for portability trouble and collisions in classloading as you've encountered now. The libraries in webapp have precedence in classloading. If theservlet-api.jar
is encountered there, it is in turn looking for its dependencies there, but they were apparently missing in there.
You must remove any appserver-specific libraries from the webapp's Webapp/WEB-INF/lib
. You shouldonly put webapp-specific libraries in there. Keep appserver-specific libraries in the appserver's own default classpath, which is theTomcat/lib
in your case. Keep it untouched. You can at most add libraries which you'd like to share among all webapps in there, or even better, configure theshared.loader
inTomcat/conf/catalina.properties
for that.
Also remove any appserver-specific and webapp-specific libraries from the JDK/lib
and JRE/lib
folders, if any. I've seen too often that some starters move/copy the libraries there because "it otherwise doesn't compile". You should never copy non-JRK/JRE-specific libraries in there. It is recipe for portability trouble as well. When compiling classes with javac
, you should use the-cp
argument to specify the dependent libraries.
Update: in case of an IDE (you seem to use one as you're talking about "build path"), you need to associate the web project with an application server. In Eclipse for example, you have the option to do that during creation of aDynamic Web Project. You need to integrate the server instance in Eclipse prior to project creation. You can do that through theServers
view (assuming that you're usingEclipse for Java EE developers, else upgrade). You can also change it afterwards through theServers entry in the project properties. Choose one which you'd like to use as the "default" server and then its libraries will automagically be included in the project's build path. There's absolutely no need to copy/move them somewhere else. See alsoHow do I import the javax.servlet API in my Eclipse project?
As other answers say, this is because your WAR includes the servlet API classes, but it should not do so.
If you are using Maven to build your project you will want to tell Maven to make the servlet API available when compiling and testing, but not to include it in the WAR. As theMaven documentation about dependency scope says, you should use provided
scope for the Servlet API:
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency>
You might also have to explicitly exclude the Servlet API as a transitive dependency, if some of your dependencies pull in the Servlet API as a compile dependency:
<dependency> <groupId>com.example</groupId> <artifactId>frob-driver-core</artifactId> <version>1.0.1</version> <exclusions> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> </exclusions> </dependency>
- 关于eclipse+tomcat调试时,Servlet Jar not Loaded的问题
- eclipse启动tomcat时servlet-api.jar jar not loaded
- servlet.jar not loaded
- 解决Eclipse maven servlet-api-2.5.jar jar not loaded问题
- Tomcat出现validateJarFile-jar not loaded问题
- myeclipse+tomcat jar包冲突导致jsp编译问题及/WEB-INF/lib/ servlet-api.jar) - jar not loaded 问题
- eclipse中tomcat启动时jar not loaded,\WEB-INF\classes\下无class文件
- servlet.jar--jar not loaded错误
- jar not loaded servlet-api.jar
- servlet.jar--jar not loaded错误
- servlet.jar--jar not loaded错误
- tomcat jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.
- 关于MySql在调试过程中出现Driver not loaded Driver not loaded的问题的解决办法
- 启动Tomcat报错- jar not loaded. Offending class: javax/servlet/Servlet.class
- tomcat启动的时候报 validateJarFile jar not loaded
- tomcat启动的时候报 validateJarFile jar not loaded
- servlet-api-2.4.jar not loaded
- servlet-api-2.4.jar not loaded解决方法
- C# WinFrom捕获按键按下事件(二)
- ThreadPoolExecutor分析
- Java 中int与byte数组转换详解
- 怎么查看别人的QQ聊天记录?QQ1622863529
- nginx的反向代理缓存
- 关于eclipse+tomcat调试时,Servlet Jar not Loaded的问题
- 微信语音被删除还可以恢复吗?QQ1622863529
- 表关联的类型和区别
- Oracle start with.connect by prior子句实现递归查询
- 陌陌语音被删除怎么才可以恢复?QQ1622863529
- Kconfig、Makefile、.config 与编译内核模块添加 -- linux内核
- Swift 方法的多面性
- JS中Null与Undefined的区别
- linux常用命令