6

I'm working on a Java project and building it with Maven (m2e). When I do a mvn clean install I get this error first thing:

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.

First thing is that the logging seems to be fine (it's very basic). But I don't like errors in my build so I followed the URL. It says basically that the class can be found in one of several packages, so I added slf4j-simple to my dependencies. I didn't know which version to use, so I got the latest (1.7.1). The error didn't go away.

It seems that one of my dependencies (JXL) needs log4j version 1.2.14 and this is what needs slf4j. I don't think I can change this (can I?). My thought is that maybe the slf4j is the wrong version but I don't know how to figure out what version log4j needs.

So first, do I even have a problem? And second, even if I don't, is there a way to get rid of the warnings?

Here is the output of mvn dependency:tree:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ dpt ---
[INFO] com.nike.dpt:dpt:war:1.3-SNAPSHOT
[INFO] +- javax.servlet:jsp-api:jar:2.0:provided
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet:jstl:jar:1.2:runtime
[INFO] +- net.sourceforge.jexcelapi:jxl:jar:2.6.12:compile
[INFO] |  \- log4j:log4j:jar:1.2.14:compile
[INFO] +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- org.springframework:spring-core:jar:3.1.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-tx:jar:3.1.2.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.1.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-beans:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:3.1.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.1.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.1.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.1.0.RELEASE:compile
[INFO] +- com.vaadin:vaadin:jar:6.8.2:compile
[INFO] +- com.google.gwt:gwt-user:jar:2.4.0:provided
[INFO] |  +- javax.validation:validation-api:jar:1.0.0.GA:provided
[INFO] |  \- javax.validation:validation-api:jar:sources:1.0.0.GA:provided
[INFO] +- org.aspectj:aspectjrt:jar:1.7.0:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.7.0:compile
[INFO] +- junit:junit:jar:4.10:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] +- org.mockito:mockito-all:jar:1.9.0:test
[INFO] +- cglib:cglib-nodep:jar:2.2.2:compile
[INFO] +- com.oracle:ojdbc14:jar:10.2.0.4.0:compile
[INFO] +- org.vaadin.addons:filteringtable:jar:0.5.3:compile
[INFO] +- org.vaadin.addons:popupbutton:jar:1.2.1:compile
[INFO] \- org.slf4j:slf4j-simple:jar:1.7.1:compile
[INFO]    \- org.slf4j:slf4j-api:jar:1.7.1:compile

I am running in the Eclipse (Juno) IDE using the Maven plugin (m2e). The CLI I am using for Maven is mvn clean package taomcat7:run or mvn clean install tomcat7:run. When I invoke Maven from a command line I do not see the slf4j error, so maybe this has to do with the m2e or Eclipse setup.

ksnortum
  • 2,809
  • 4
  • 27
  • 36
  • 1
    Did you include SLF4J in maven dependency and for deploy path, it seems SLF4J is not found in deployment folder. – Elbek Sep 27 '12 at 16:51
  • I'm not sure what the deployment folder is, sorry. I'm in Eclipse and I can see the slf4j jar under Maven Dependencies. – ksnortum Sep 27 '12 at 16:54
  • Artifact, when you deploy the project, you need to copy all required libs under WEB-INF/lib folder. If it is not found there then jar is missing – Elbek Sep 27 '12 at 17:13
  • The jar definitely is in `target/dpt/WEB-INF/lib'. Is there somewhere else to look? – ksnortum Sep 27 '12 at 17:53
  • 1
    If you do not change web server output folder then the folder should be: `workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\your_app_name\WEB-INF\lib` You can go and check it – Elbek Sep 27 '12 at 18:02
  • `workspace\.metadata\.plugins\org.eclipse.wst.server.core` is empty. Would a change of web server output folder be in the `maven-war-plugin` section? I don't see any `` tab there. – ksnortum Sep 27 '12 at 18:23
  • How are you building the project with maven or with eclipse? – Elbek Sep 27 '12 at 18:24
  • It happens with Eclipse and m2e but not with `mvn install` at the command line. Is it an m2e problem? – ksnortum Sep 27 '12 at 18:44
  • Please provide more info on your runtime environment. Which server app server are you deploying with? – Ceki Sep 28 '12 at 16:51
  • Maybe that is not a solution at all, but I was able to help myself by running my project using Apache tomcad. – Bogdan Onyshenko Sep 25 '21 at 19:35

4 Answers4

8

The error message is not related to your project. It is an m2e problem and does not cause any harm. You won't see it if you build on the command-line outside Eclipse.

There is a bug about this but unfortunately they are rather willing to confuse peole than to fix it:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=387064

unguiculus
  • 413
  • 3
  • 8
1

The output of mvn dependency:tree clearly shows that both slf4j-api and slf4j-simple are on your class path. The fact that SLF4J complains about not finding org.slf4j.impl.StaticLoggerBinder means that there is another copy of slf4j-api.jar somewhere on your classpath and this is the copy being loaded into memory (rather than the copy of slf4j-api.jar in com.nike.dpt:dpt:war). Under such circumstances, because of the class loader delegation model of many application servers, the classes loaded by the server's copy of slf4j-api cannot find the classes packaged in slf4j-simple.jar located in your web-app. Typically this occurs when a copy of slf4j-api.jar is placed in the application server's lib/ folder as opposed to the WEB-INF/lib/ folder of your web-application.

What is your runtime environment? application server?

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • I went into `target/dpt/WED-INF/lib` and I only saw `slf4j-api-1.7.1.jar` and `slf4j-simple-1.7.1.jar`. Is this where I should look, or elsewhere? – ksnortum Sep 27 '12 at 17:52
  • The slf4j error code page say, "SLF4J API is desinged to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings." I'm not seeing a list of locations, so can we assume that I don't have multiple jars? – ksnortum Sep 27 '12 at 18:14
  • You should look at your application server's lib/ folder. By app servers, I mean Tomcat, Jetty, JBoss, Weblogic, etc. Hoint for the folders: $TOMCAT_HOME/lib, $JBOSS/server/lib/, $WEBLOGIC/some/path, etc. The error you are seeing seeing is reported when "the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory" because it could not be found. It is unrelated to multiple bindings. – Ceki Sep 28 '12 at 07:27
  • I edited my question to include runtime environment. I'm using a Maven plugin tomcat7. I get the error only when I'm launching the app server from the IDE (Eclipse), not when I run Maven from the command line. My CLI is `mvn clean package tomcat7:run` – ksnortum Sep 28 '12 at 17:28
  • Sounds like a bug in m2e or in the t7 plugin. – Ceki Sep 28 '12 at 18:21
0

Follow this rule:

Place one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar
Anshu
  • 7,783
  • 5
  • 31
  • 41
0

Try to configure these dependencies in your pom:

org.slf4j:slf4j-api:jar:1.7.1:compile
org.slf4j:slf4j-log4j12:jar:1.7.1:runtime

slf4j-api is the log API and is needed in compile time, whereas slf4j-log4j12 is the implementation (using log4j) and it's needed in runtime.

polypiel
  • 2,321
  • 1
  • 19
  • 27
  • You explanation is surprisingly plausible but unfortunately quite wrong. As far as I know, the "runtime" scope differs from "compile" in that a dependency in runtime scope is not transitive (which should not make a difference in this case). Thus, scoping slf4j-log4j as runtime scope should have no impact on the problem at hand. – Ceki Sep 28 '12 at 16:48