Tomcat 类路径上有 jar 的 webapp NoClassDefFoundError
Tomcat webapp NoClassDefFoundError with jar on classpath
部署新的 Web 应用程序时遇到 NoClassDefFoundError。我正在使用现有的独立应用程序并将其转换为 Web 应用程序,但是当抛出 class not found 时,通常是因为 jar 不在 class 路径上...
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 可能存在于服务器上,并且在我的应用程序部署时发生冲突。我在服务器上找不到任何 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
有没有我忽略的东西?
可能的原因:
- Tomcat 不是 运行 作为 root
- Commons-logging-1.1.1.jar里面没有classorg.apache.commons.logging.LogFactory.
升级到 commons-logging 1.2 解决了这个问题。我正在使用 maven 来管理我的依赖项,但仍然困惑为什么 1.1.1 不起作用但无论如何。
部署新的 Web 应用程序时遇到 NoClassDefFoundError。我正在使用现有的独立应用程序并将其转换为 Web 应用程序,但是当抛出 class not found 时,通常是因为 jar 不在 class 路径上...
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 可能存在于服务器上,并且在我的应用程序部署时发生冲突。我在服务器上找不到任何 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
有没有我忽略的东西?
可能的原因:
- Tomcat 不是 运行 作为 root
- Commons-logging-1.1.1.jar里面没有classorg.apache.commons.logging.LogFactory.
升级到 commons-logging 1.2 解决了这个问题。我正在使用 maven 来管理我的依赖项,但仍然困惑为什么 1.1.1 不起作用但无论如何。