Failed to load class.sorg.slf4j.impl.StaticLoggerBinder class error in java project?

I get the error Failed to load class "org.slf4j.impl.StaticLoggerBinder" . I want to write the recorder to a file. I used log4j.jar and am using apache tomcat server.

 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. 
+5
source share
4 answers

Primarily. Regarding the dependencies.

To add SLF4J, you must put ONE and only ONE of these dependencies in your pom.xml. It depends on which implementation you prefer to use. Each dependency that you add to pom.xml is automatically added to the classpath. If one of the following dependencies is provided by another dependency, you can omit it. Remember that you should include only one, even if the dependency is provided by another dependency. Please note that I did not specify the version from the dependencies. Use the latest available version.

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

Now about the annoying error you get when creating your maven project. If after having only one of the above dependencies, you still get SLF4J: the class "org.slf4j.impl.StaticLoggerBinder" could not be loaded. then you encounter an error with m2e.

Eclipse Juno and Indigo, when using the nested version of maven (m2e), do not suppress the SLF4J message: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behavior is present in version m2e 1.1.0.20120530-0009 onwards.

Although this is indicated as an error, your logs will be saved normally. The highlighted error will still be present until this error is fixed. See the m2e support site for more details .

The current available solution is to use an external version of maven, not a bundled version of Eclipse. You can find about this solution and more about this error in the question below, which, I think, describes the same problem that you are facing.

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

+13
source

you need to add slf4j jar or dependency on your project

+2
source

Please import slf4j-api-1.6.6.jar for your project. 1.Enter the following code into your java class

 private Logger logger = LoggerFactory.getLogger(this.getClass()); 

2.import the following:

 import org.slf4j.Logger; import org.slf4j.LoggerFactory; 

Now you can use logger.info (); to print anything.

0
source

There is no explicit example in the manual of how to use log4j and sl4j together. But there are many unofficial ones, I like this one: http://www.javavillage.in/slf4j-with-log4j.php

Pay attention to only two Maven Deps. There is no explicit log4j dep, it loads automatically.

Also (and it cost me 1 hour 14 minutes) some versions of sl4j are not stable, and this is important. Version 1.8 beta (yes .. beta) does not work. So I used 1.7.13 and it works.

So, check for Maven Deps, it should be like this:

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

The default configuration location is the resource folder. For example, for main sources:

 project/src/main/resources 

or for testing:

 project/src 

Hooray!

0
source

All Articles