Withheld
Withheld

Reputation: 4703

Failed to load class "org.slf4j.impl.StaticLoggerBinder" -- Which classpath?

My pom.xml contains only one reference to SLF4J:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.5.10</version>
    </dependency>

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.

I checked that URL and indeed it provides a solution: "Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. "

My question is: which classpath?

I found quite a few postings on the subject here on SO, but they all quote the same answer: "place ... on the class path".

Which classpath?

Upvotes: 23

Views: 58085

Answers (3)

Girdhar Singh Rathore
Girdhar Singh Rathore

Reputation: 5615

If you are using gradle than add following dependency in build.gradle.kts

 dependencies {
    implementation("ch.qos.logback:logback-classic:1.2.11")         
 }

Upvotes: 0

Shant Dashjian
Shant Dashjian

Reputation: 1010

Problem:

I'm using Maven to manage my dependencies. In my case, the reason I was getting this error was because I had more than one slf4j-simple jar in my system on my class path. The SLF4J documentation states:

Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Solution:

  • Search for the following jars in your file system and remove all copies other than the one in .m3:
    1. slf4j-nop
    2. slf4j-simple
    3. slf4j-log4j12
    4. slf4j-jdk14
    5. logback-classic

Upvotes: 0

Konstantinos Margaritis
Konstantinos Margaritis

Reputation: 3247

First of all in order to add SLF4J you should put ONE and only ONE of these dependencies in your pom.xml. It depends on what implementation you choose to use. Every dependency you add in the pom.xml is added automatically in the classpath. As long as you are using Eclipse there is no need to modify the system's %CLASSPATH%?

<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version></version>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-jdk14</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>

Last but not least you will have the error SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

Eclipse Juno and Indigo, 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 in order to suppress this message 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.

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

Upvotes: 23

Related Questions