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"/>
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With