Zahid Nisar
Zahid Nisar

Reputation: 882

Maven SLF4J: Class path contains multiple SLF4J bindings

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

Upvotes: 31

Views: 92394

Answers (5)

Akitha_MJ
Akitha_MJ

Reputation: 4294

This Works !! Update the porm.xml

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

Upvotes: 1

Atul Yadav
Atul Yadav

Reputation: 29

You can go to POM.xml , open Dependency Hierarchy and find slf4j entries.Except one exclude rest of them by right clicking "exclude maven artifact"

Upvotes: 2

Wouter
Wouter

Reputation: 4016

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>

Upvotes: 65

Binita Bharati
Binita Bharati

Reputation: 5898

This error means that you have multiple implementations of SLF4J in your classpath. Look for what the errors are specifically saying. i.e : SLf4J: Found binding in..... (This will print all the jar files where it found instances of StaticLoggerBinder.class). Eliminate all such jars from your classpath, except the jar whose StaticLoggerBinder.class implementation you need.

Upvotes: 5

Angelo Immediata
Angelo Immediata

Reputation: 6944

It seems you have several implementation of SLF4J; you should exclude all the not necessary ones

Upvotes: 6

Related Questions