在Tomcat7中设置类路径以解决NoClassDefNotFound错误

时间:2014-04-06 20:54:47

标签: java tomcat web-applications tomcat7 classpath

我最近将我在eclipse中构建的Web应用程序部署到AWS ec2实例。在eclipse中工作得很好,但在我的服务器上出现了NoClassDefNotFound错误。我在我的servlet中编写了一个测试main方法,并且能够通过运行

来消除错误
java -cp .:(class paths to all imported classes). packageName.myservlet

所以我的问题是如何配置tomcat7以包含我为使我的servlet正常运行所做的类路径,谢谢。

Apr 06, 2014 10:53:37 PM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/ArtGallery]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with JAR file [/usr/share/java/tomcat7/log4j.jar], exists: [false] canRead:[false]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with JAR file [/usr/share/java/tomcat7/log4j.jar], exists: [false] canRead:[false]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with JAR file [/usr/share/tomcat7/usr/lib/jvm/jre/lib/j2ee.jar]exists:[false],canRead:[false]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory[/usr/share/tomcat7/usr/share/tomcat7/webapps/ArtGallery/WEB-INF/lib], exists: [false], isDirectory: [false], canRead: [false]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with JAR file [/usr/share/tomcat7/usr/lib/jvm/jre/lib/j2ee.jar], exists: [false], canRead: [false]
Apr 06, 2014 10:53:52 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory[/usr/share/tomcat7/usr/share/tomcat7/webapps/ArtGallery/WEB-INF/lib], exists: [false], isDirectory: [false], canRead: [false]
Apr 06, 2014 10:53:53 PM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
SEVERE: Exception processing Global JNDI Resources
javax.naming.NamingException: The markup in the document following the root element must be well-formed.

这里有一些我在catalina.out中发现的可疑警告,下面是我可以用来让servlet运行我的test main方法。

java -classpath .:/usr/lib/jvm/jre/lib/j2ee.jar:/usr/share/tomcat7/webapps/ArtGallery/WEB-INF/lib/* ArtworkServlet/ArtworkDB

1 个答案:

答案 0 :(得分:1)

查看日志文件,您的tomcat安装似乎存在问题。 请参阅评论以获取更多信息。

作为暴力解决方案我建议重新安装tomcat。

使用类路径不是解决问题的正确方法