在classpath上使用jar的Tomcat webapp NoClassDefFoundError

时间:2015-10-13 21:31:14

标签: java tomcat noclassdeffounderror classnotfoundexception apache-commons-logging

部署新的webapp时遇到NoClassDefFoundError。我正在使用现有的独立应用程序并将其转换为webapp但是当找不到找到的类时,通常会导致jar不在类路径上...

SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.web.context.ContextCleanupListener.<clinit>(ContextCleanupListener.java:43)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4886)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4750)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
... 19 more

Commons-logging-1.1.1.jar在我的tomcat / webapps / app / WEB-INF / lib目录

/var/lib/tomcat6/webapps# ls jmanager/WEB-INF/lib/ | grep commons
commons-beanutils-1.8.3.jar
commons-beanutils-core-1.7.0.jar
commons-cli-1.2.jar
commons-codec-1.9.jar
commons-collections-3.2.1.jar
commons-configuration-1.5.jar
commons-digester-1.8.jar
commons-fileupload-1.2.2.jar
commons-httpclient-3.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
commons-management-1.0.jar

我的另一个想法可能是服务器上存在jar,当我的app部署时它会发生冲突。我在服务器上找不到任何commons-logging jar,其他共享文件夹都是空的。

/usr/share/tomcat6/lib# ls -al
total 8
drwxr-xr-x 2 tomcat6 tomcat6 4096 Aug 25 14:32 .
drwxr-xr-x 7 tomcat6 tomcat6 4096 Aug 25 14:32 ..
lrwxrwxrwx 1 root    root      37 Jun 22 09:29 annotations-api.jar -> ../../java/annotations-api-6.0.35.jar
lrwxrwxrwx 1 root    root      34 Jun 22 09:29 catalina-ant.jar -> ../../java/catalina-ant-6.0.35.jar
 lrwxrwxrwx 1 root    root      33 Jun 22 09:29 catalina-ha.jar -> ../../java/catalina-ha-6.0.35.jar
lrwxrwxrwx 1 root    root      30 Jun 22 09:29 catalina.jar -> ../../java/catalina-6.0.35.jar
lrwxrwxrwx 1 root    root      37 Jun 22 09:29 catalina-tribes.jar -> ../../java/catalina-tribes-6.0.35.jar
lrwxrwxrwx 1 root    root      27 Jun 22 09:29 commons-dbcp.jar -> ../../java/commons-dbcp.jar
lrwxrwxrwx 1 root    root      27 Jun 22 09:29 commons-pool.jar -> ../../java/commons-pool.jar
lrwxrwxrwx 1 root    root      25 Jun 22 09:29 el-api.jar -> ../../java/el-api-2.1.jar
lrwxrwxrwx 1 root    root      31 Jun 22 09:29 jasper-el.jar -> ../../java/jasper-el-6.0.35.jar
lrwxrwxrwx 1 root    root      28 Jun 22 09:29 jasper.jar -> ../../java/jasper-6.0.35.jar
lrwxrwxrwx 1 root    root      18 Jun 22 09:29 jasper-jdt.jar -> ../../java/ecj.jar
lrwxrwxrwx 1 root    root      26 Jun 22 09:29 jsp-api.jar -> ../../java/jsp-api-2.1.jar
lrwxrwxrwx 1 root    root      30 Jun 22 09:29 servlet-api.jar -> ../../java/servlet-api-2.5.jar
lrwxrwxrwx 1 root    root      35 Jun 22 09:29 tomcat-coyote.jar -> ../../java/tomcat-coyote-6.0.35.jar
lrwxrwxrwx 1 root    root      36 Jun 22 09:29 tomcat-i18n-es.jar -> ../../java/tomcat-i18n-es-6.0.35.jar
lrwxrwxrwx 1 root    root      36 Jun 22 09:29 tomcat-i18n-fr.jar -> ../../java/tomcat-i18n-fr-6.0.35.jar
lrwxrwxrwx 1 root    root      36 Jun 22 09:29 tomcat-i18n-ja.jar -> ../../java/tomcat-i18n-ja-6.0.35.jar

我有什么东西可以俯瞰吗?

2 个答案:

答案 0 :(得分:0)

可能的原因:

  • Tomcat未以root身份运行
  • Commons-logging-1.1.1.jar里面没有org.apache.commons.logging.LogFactory类。

答案 1 :(得分:0)

升级到commons-logging 1.2解决了这个问题。我使用maven来管理我的依赖关系,仍然混淆为什么1.1.1无法正常工作。