Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven SLF4J: Class path contains multiple SLF4J bindings

Tags:

java

maven

I am getting following runtime Exception while running my java code. Could someone please help me resolve the binding conflicts.

    SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-android-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jcl-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-nop-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-simple-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.AndroidLoggerFactory] Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Fatal error in constructor!     ... 2 more 
like image 812
Zahid Nisar Avatar asked Apr 06 '14 15:04

Zahid Nisar


People also ask

How do I fix SLF4J class path contains multiple SLF4J bindings?

If you are looking for quick solution for this issue, you need to find out how log4j is present on your path. run mvn dependency:tree and figure out the maven dependency and exclude log4j with snippet below to that dependency in your pom. xml . This should resolve SLF4J: Class Path Contains Multiple SLF4J Bindings.

What are SLF4J bindings?

Bindings are basically implementations of a particular SLF4J class meant to be extended to plug in a specific logging framework. By design, SLF4J will only bind with one logging framework at a time. Consequently, if more than one binding is present on the classpath, it will emit a warning.


1 Answers

Run mvn dependency:tree and search which dependency have the slf4j implementations you do not want, then exclude them with a dependency exclusion like:

<dependency>     <groupId>org.someexternallib</groupId>     <artifactId>someexternallibartifact</artifactId>     <version>...</version>      <exclusions>        <exclusion>            <groupId>org.slf4j</groupId>           <artifactId>slf4j-log4j12</artifactId>        </exclusion>        <exclusion>            <groupId>log4j</groupId>           <artifactId>log4j</artifactId>       </exclusion>     </exclusions>  </dependency> 
like image 143
Wouter Avatar answered Sep 19 '22 23:09

Wouter