简体   繁体   中英

Tomcat webapp NoClassDefFoundError with jar on classpath

Experiencing a NoClassDefFoundError when deploying a new webapp. I'm taking an existing standalone app and converting it to be a webapp but when a class not found is thrown it's usually cause the jar isn't on the classpath...

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 is in my tomcat/webapps/app/WEB-INF/lib dir

/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

My other thought was maybe the jar exists on the server and it's colliding when my app deploys. I can't find any commons-logging jar on the server and the other share folders are all empty.

/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

Is there something I'm overlooking?

Possible causes:

  • Tomcat is not running as root
  • The Commons-logging-1.1.1.jar does not have the class org.apache.commons.logging.LogFactory inside.

Upgrading to commons-logging 1.2 solved the issue. I'm using maven to manage my dependencies, still confused why 1.1.1 didn't work but whatever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM