I have a servlet in a jar file which I want to deploy to my Tomcat 6 instance. I did the following things:
- added a servlet declaration in my root web.xml
- added a servlet-mapping in the root web.xml
- put my jar file in /tomcat/lib
- re-started my server
I am getting the following error when I direct to my servlet
javax.servlet.ServletException: Wrapper cannot find servlet class com.mypackage.myServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.ClassNotFoundException: com.mypackage.myServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http开发者_开发技巧11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
This says to me that my web.xml is configured correctly and I am successfully hitting the right URL pattern. So the question is... where do I put a servlet jar file in Tomcat 6 so it gets picked up in the CLASSPATH?
TIA
Your servlet JAR files goes in the WAR's lib
directory, not in the top-level Tomcat lib
directory, i.e.
<war-root>
/WEB-INF
web.xml
/lib
myservlet.jar
Although this is not the normal practice, it should work fine. Because it should in theory work, I've tested it locally and it works fine (Tomcat 6.0.20 and 7.0.5). You've probably a typo in the <servlet-class>
. The classname of your servlet namely starts with a lowercase, which goes totally against the Java naming conventions. Try
<servlet-class>com.mypackage.MyServlet</servlet-class>
instead.
If that doesn't fix it, then unpack the JAR with some ZIP/RAR tool and verify if the com/mypackage/MyServlet.class
file is present.
If the file is actually present, then you're probably using some IDE which has only a specific subset of the jars of Tomcat/lib
in a copy of Tomcat which is controlled/managed by the IDE. Try deploy and run Tomcat standalone the hard way in command console.
精彩评论