Reputation: 396
My web project was running fine till yesterday however today when I start my tomcat server 7 it fails to start with below error in eclipse:
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CiscoQA_Automation_Framework]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 7 more
Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:192)
at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:157)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1577)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1281)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5419)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
... 19 more
After referring here and few other links I have cleaned up WEB-INF/lib and classpath and then added "log4j-web-2.3.jar" and "log4j-1.2.17.jar" in both WEB-INF/lib and class path. I have tried cleaning up the project and tomcat working directory as well nothing worked.
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
Upvotes: 5
Views: 12201
Reputation: 1312
Sometimes this can happen when there are multiple log4j versions in your war and they conflict. If this is a maven build use mvn dependendency:tree to make sure that you are not transitively pulling in multiple versions of log4j. I'd start with looking in your $TOMCAT_HOME/webapps/{your_app_name_goes_here}/WEB-INF/lib directory. I'd guess that the reason it stopped working today is because the class loader decided to load some other version of log4j today first.
Upvotes: 2
Reputation: 351
NoClassDefFound error is generally not related to classpath issues so focussing there is futile. I recommend deploy ur web app in tomcat with default settings and then and customizations one by one to find the problem.
Upvotes: 0
Reputation: 159096
You have a custom <Listener>
in your server.xml
that references a class that has a static dependency on Log4j, and you didn't add the Log4j jar file to Tomcats classpath, i.e. to the $TOMCAT_HOME/lib
(or $TOMCAT_BASE/lib
) folder.
Either remove the listener or add the missing jar file.
Update
You say you added log4j-web-2.3.jar
and log4j-1.2.17.jar
, but the error message says that org.apache.logging.log4j.Logger
is missing.
log4j-1.2.17.jar
has a org.apache.log4j.Logger
, so that's the wrong version of Log4j.
log4j-web-2.3.jar
contains a Log4jServletContainerInitializer
in package org.apache.logging.log4j.web
. It is automatically loaded by Tomcat simply by being there. This is the class that needs org.apache.logging.log4j.Logger
.
org.apache.logging.log4j.Logger
can be found in log4j-api-2.3.jar
, so you need this file, but it is just the API. You also need log4j-core-2.3.jar
, which is the actual Log4J 2 implementation.
If you don't have code using the Log4j 1 API, remove log4j-1.2.17.jar
. If you do have code using the old API, replace that file with log4j-1.2-api-2.3.jar
, which redirects old API calls to the new API. This eliminates the need for configuring both, and allow a single log file regardless of API version used.
Summary: You need the following files:
log4j-api-2.3.jar
log4j-core-2.3.jar
log4j-web-2.3.jar
log4j-1.2-api-2.3.jar
(replaces log4j-1.2.17.jar
, only add if needed by old code)While you are at it, upgrade to the latest version (2.5).
Upvotes: 4
Reputation:
There is a problem with the LifecycleListener interface in your program. Often it is particularly difficult to understand the cause of LifecycleListener problems, as there are generally numerous dependencies. My recommendation would be to scrap the contents of the file containing your LifecycleListener and to make sure to remove any decencies which may rely on it. Then reconstruct from the beginning.
This may not be the quickest route to fixing the error, but it is very likely to be be the most effective, and the one most likely to stop you from having further errors in future.
Upvotes: 0