SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". in a Maven Project

Kayser picture Kayser · Sep 17, 2012 · Viewed 154.2k times · Source

I have a dependency for SLF4J. I am getting this error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Here is my maven entry:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

Where is the problem?


EDIT: Without log4j dependency I get the following exception

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
    at org.apache.bval.jsr303.ConfigurationImpl.<clinit>(ConfigurationImpl.java:50)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:228)
    at org.apache.bval.jsr303.ApacheValidationProvider.createGenericConfiguration(ApacheValidationProvider.java:66)
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:173)
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:50)
    at com.daimler.zv9.basic.entity.AbstractEntity.<clinit>(AbstractEntity.java:73)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:228)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:195)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:168)

EDIT2: It is an example MAVEN Tree that I get

[INFO] com.myCompany.abc:ABC_Document:ejb:0.0.1-SNAPSHOT
[INFO] +- com.myCompany.abc:ABC_Basic:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.myCompany.iap:javax.j2ee:jar:5.0.0:provided
[INFO] +- com.myCompany.iap:logging:jar:5.0.0:provided
[INFO] +- com.myCompany.iap:util:jar:5.0.0:provided
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.6:compile
[INFO] \- org.mockito:mockito-all:jar:1.9.0:test

Answer

Konstantinos Margaritis picture Konstantinos Margaritis · Nov 7, 2012

I am assuming you are using Eclipse as your developing environment.

Eclipse Juno, Indigo and Kepler when using the bundled maven version(m2e), are not suppressing the message SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behaviour is present from the m2e version 1.1.0.20120530-0009 and onwards.

Although, this is indicated as an error your logs will be saved normally. The highlighted error will still be present until there is a fix of this bug. More about this in the m2e support site.

The current available solution is to use an external maven version rather than the bundled version of Eclipse. You can find about this solution and more details regarding this bug in the question below which i believe describes the same problem you are facing.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error