在 Tomcat 6 中,我应该将 servlet jar 文件放在哪里?
我的 jar 文件中有一个 servlet,我想将其部署到我的 Tomcat 6 实例。我做了以下事情:
- 在我的根 web.xml 中添加了 servlet 声明
- 在根 web.xml 中添加了 servlet 映射
- 将我的 jar 文件放入 /tomcat/lib
- 重新启动我的服务器
当我直接操作时,出现以下错误到我的 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(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
这对我来说,我的 web.xml 配置正确,并且我成功地命中了正确的 URL 模式。所以问题是...我应该将 servlet jar 文件放在 Tomcat 6 中的哪里,以便在 CLASSPATH 中获取它?
TIA
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(Http11Protocol.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 servlet JAR 文件位于 WAR 的
lib
目录中,而不是位于顶级 Tomcatlib
目录中,即Your servlet JAR files goes in the WAR's
lib
directory, not in the top-level Tomcatlib
directory, i.e.虽然这不是正常做法,但应该可以正常工作。因为理论上它应该可以工作,所以我在本地测试了它并且工作正常(Tomcat 6.0.20 和 7.0.5)。您可能在
中出现拼写错误。 servlet 的类名以小写字母开头,这完全违背了 Java命名约定。尝试一下。
如果这不能解决问题,请使用一些 ZIP/RAR 工具解压 JAR,并验证
com/mypackage/MyServlet.class
文件是否存在。如果该文件确实存在,那么您可能正在使用某些 IDE,该 IDE 在由 IDE 控制/管理的 Tomcat 副本中仅包含
Tomcat/lib
的 jar 的特定子集。尝试在命令控制台中以困难的方式部署并独立运行 Tomcat。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. Tryinstead.
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.