Vinod Vinod - 1 year ago 311
Java Question

Unable to start tomcat 7: Caused by: java.lang.NoClassDefFoundError

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(
... 7 more
Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at org.apache.catalina.startup.WebappServiceLoader.loadServices(
at org.apache.catalina.startup.WebappServiceLoader.load(
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(
at org.apache.catalina.startup.ContextConfig.webConfig(
at org.apache.catalina.startup.ContextConfig.configureStart(
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
... 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="" />
<!--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"/>

Answer Source

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.


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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download