Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple SLF4J bindings with m2e in Eclipse 2020-06

Got a problem getting slf4j working for me with m2e. This is not the first time to state this problem. However, others have a more specific case and still no answer.

I installed Eclipse-jee fresh. For test I created a simplest maven project from maven-archetype-quickstart. It simply prints out Hello World!

Although applying m2e it compiles and runs fine, I get the messages in red

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/rschumacher/install/eclipse-jee/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/C:/Users/rschumacher/install/eclipse-jee/configuration/org.eclipse.osgi/5/0/.cp/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.SimpleLoggerFactory]

This happens with any maven project when performing run as/Maven test.
It doesn't help to look at the dependency:tree of the pom.xml, as the conflicting bindings are with m2e and osgi (as far as I can interprete the messages).

As result, slf4j ignores the configuration and is no longer usable from within Eclipse with m2e installed.
If I start mvn test from a commandline, no such messages appear. slf4j logging is working as it should.

Do you got any idea or workaround in order to have slf4j working again with m2e?

like image 426
ngong Avatar asked Sep 05 '20 15:09

ngong


People also ask

How do I resolve 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

With the help of Nickel Cao's answer, I was (eventually) able to fix the SLF4J error/warning messages you are describing. However, Nickel's solution only fixed the default Maven Run As goals. My custom Maven build goals - the only goals I ever use - also had to be updated before the SLF4J errors went away.

NOTE: I fixed the problem in Eclipse 2020-09, not 2020-06.

Here's how I did it, with some screenshots. (Sorry, I don't have the reputation to embed them.)

  1. Add your external Maven installation directory in Window -> Preferences -> Maven -> Installations: Screenshot of Maven Installations dialog (I'm pretty sure the checkbox is how you select the default Maven runtime..)
  2. Open the Run Configurations dialog by clicking Run As -> Run Configurations from the Project's context menu: Screenshot of Project's Run As context menu
  3. Update each of your custom Maven build configurations to use the external Maven Runtime: Screenshot of Run Configurations dialog

Once I had performed this last step, my custom Run-As Maven builds stopped generating the SLF4J errors: Screenshot of victory

Cheers!

like image 110
JMR Avatar answered Sep 21 '22 12:09

JMR