23

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?

  • The system's %CLASSPATH%? (I don't have one! I will need to create it specifically for this)
  • Eclipse's project .classpath? (I think I tried this but it didn't help)
  • Other?

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?

Community
  • 1
  • 1
Withheld
  • 4,603
  • 10
  • 45
  • 76
  • 1
    Are you using maven with Eclipse.? – Konstantinos Margaritis Dec 12 '12 at 13:19
  • @KonstantinosMargaritis Yes, I am using Maven with Eclipse: `1.` Eclipse 3.7.2 `2.` Maven 2.2.1 `3.` m2e plugin 1.2.0.20120903-1050. Any idea how to resolve this error *without* defaulting to the no-operation (NOP) logger implementation SLF4J? Thanks. – Withheld Dec 12 '12 at 13:33
  • 1
    Are you using logback or something else. I am asking in order to tell you about the dependencies. – Konstantinos Margaritis Dec 12 '12 at 13:43
  • @KonstantinosMargaritis What is "logback"? How can I check if I am using it? – Withheld Dec 12 '12 at 13:56
  • 1
    Logback is an implementation that can be used with slf4j. If you dont know it, it means you are not using it. I suggest you take a look at my answer here http://stackoverflow.com/questions/12382897/optional-printing-of-stack-trace-in-java/12389287#12389287 about logback and slf4j. My answer contains also classpath settings but you dont need that. – Konstantinos Margaritis Dec 12 '12 at 13:59
  • 1
    @KonstantinosMargaritis I inherited this system so it would've been quite possible that I was using it unbeknownst to me. But searching through `pom.xml` didn't yield any reference to 'logback'. It found one reference only to 'slf4j' (which is what's recommended). I will continue my comment in reply to your excellent answer below. Thanks. – Withheld Dec 12 '12 at 14:19
  • I did not know that Daniel. I did not tell it in a bad way. It is easy to find out if you have it. In case you dont have any logback dependency that means you are not using it. As i see you have slf4j-jdk14 dependency so you can add the last dependency of it in your pom.xml. The last version is 1.6.6 – Konstantinos Margaritis Dec 12 '12 at 14:44
  • For those like me who are new to build tools like maven or gradle, I found out that when someone says "add to classpath" they mean that you should add a dependency to your pom.xml or build.gradle files. I solved this issue by upgrading the version of the slf4j-simple dependency I was using. – retrovius Sep 17 '19 at 13:01
  • The runtime jvm classpath... – rogerdpack Dec 18 '19 at 16:07

4 Answers4

23

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

Community
  • 1
  • 1
Konstantinos Margaritis
  • 3,237
  • 3
  • 22
  • 32
  • 3
    Thanks for this excellent answer. First, it answers my question *"which classpath?"* (no need to follow m2e's support site suggestion because `slf4j-jdk14` is already referenced in the `pom.xml`?). Second, step #3 in [this answer](http://stackoverflow.com/a/12373375/1864054) (link you provided) got rid of the error message: `Window` > `Preferences` > `Maven` > `Installations` > Uncheck `Embedded` > Add... `External`. – Withheld Dec 12 '12 at 14:48
  • @Daniel You are more than welcome.! If you need any other assist with maven or logging let me know. – Konstantinos Margaritis Dec 12 '12 at 14:56
  • A short description of the different logging frameworks can be found here: http://www.slf4j.org/manual.html#swapping – Robert Fey Jan 11 '16 at 17:30
  • 1
    @KonstantinosMargaritis, you saved my day ! Thank you. You gave a good explanation – Sharm Jul 02 '21 at 13:32
0

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
Shant Dashjian
  • 888
  • 11
  • 20
0

If you use maven you need to add this dependency:

<dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.2</version>
</dependency>

If you also use Intellij you need to check if the ch.qos.logback is extracted to the output root.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 03 '23 at 17:22
0

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

 dependencies {
    implementation("ch.qos.logback:logback-classic:1.2.11")         
 }
Girdhar Singh Rathore
  • 5,030
  • 7
  • 49
  • 67