java.lang.NoClassDefFoundError: Lorg/apache/logging/log4j/Logger; but the artifact exists
<p>I'm using Tomcat to deploy a java webapp.</p>

<p>I get a very long stacktrace, in short:</p>

<pre><code>GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/new-webapp]]
[...]
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/logging/log4j/Logger;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2509)
    at java.lang.Class.getDeclaredFields(Class.java:1819)
    at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationFilterAnnotations(WebAnnotationSet.java:105)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:64)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:335)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:782)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:306)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5150)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
    ... 20 more
[...]
</code></pre>

<p>Now, the error is pretty clear. For some reason, the log4j bundle is not in the classpath.</p>

<p>The application is a maven webapp, and the pom.xml is like this:</p>

<pre><code>&lt;project 
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.wb&lt;/groupId&gt;
    &lt;artifactId&gt;new-webapp&lt;/artifactId&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;version&gt;0.0.1&lt;/version&gt;
    &lt;properties&gt;
        &lt;log4j.version&gt;2.5&lt;/log4j.version&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;
    [...]
        &lt;!-- Logging --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
            &lt;version&gt;${log4j.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
            &lt;version&gt;${log4j.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-web&lt;/artifactId&gt;
            &lt;version&gt;${log4j.version}&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    [...]
&lt;/project&gt;
</code></pre>

<p>If I go to the project properties, under Libraries->Maven Dependencies I see this:</p>

<p><a href="https://i.stack.imgur.com/dNTEl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dNTEl.png" alt="enter image description here"></a></p>

<p>Libraries were found, downloaded and they are in the classpath.</p>

<p>I also tried to open a java class inside my project and declare</p>

<pre><code>org.apache.logging.log4j.Logger Logger;
</code></pre>

<p>No errors, the <code>Logger</code> interface is found.</p>

<p>What's going on here? Why does Tomcat fail to start even if libraries are in the classpath?</p>

<hr>

<p>Edit - this is the log4j configuration file:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Configuration status="INFO"&gt;
    &lt;Appenders&gt;
        &lt;Console name="Console" target="SYSTEM_OUT"&gt;
            &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /&gt;
        &lt;/Console&gt;
    &lt;/Appenders&gt;
    &lt;Loggers&gt;
        &lt;Root level="INFO"&gt;
            &lt;AppenderRef ref="Console" /&gt;
        &lt;/Root&gt;
    &lt;/Loggers&gt;
&lt;/Configuration&gt;
</code></pre>