Tomcat6 error: Jar not loaded - Offending class: javax/servlet/Servlet.class
I created a war file and on deployment I encountered this error:
Tomcat6 error: Jar not loaded - Offending class: javax/servlet/Servlet.class
Thankfully, I was able to resolve it easily, as I had the clue where I was going wrong. The war file created using ant build.xml of netbeans used to deploy successfully but the war created using my own build script used to fail during deployment.
The reason for failure was that I was including servlet-api.jar to the war file. This jar offends the tomcat as it already has a copy of it and doesn't expect another.
I modified my war file to success. Below is the snapshot of changes in build.xml
<target name="war" depends="compile"> <war destfile="dist/xxx.war" webxml="web/WEB-INF/web.xml"> <fileset dir="web"/> <lib dir="lib"> <exclude name="servlet-api.jar"/> </lib> <classes dir="build/classes"/> </war> </target>
Another important point to note is that ant will expect the servlet-api.jar in classpath at compile time. Hence the servlet-api.jar has to be present in the /lib directory (you cannot delete it). Hence exclude is the best solution. Can't think of any other solution. Please share if you can think of any other.








