1

I am using querydsl (which depends on sl4j-api 1.6) and arquillian-persistence-api (which depends on slf4j-jdk14 1.5.6). If I ignore in maven the older version 1.5.6 I get the following message on JBoss

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.

I am using arquillian with managed JBoss AS 7.1 for testing (Maven downloads the version from maven central and run the tests). I am also using arquillian persistence api.

What should I do to correct the given warning? I mean which dependency should I keep or how would I allow both to work properly?

I suppose this is why I am not getting any error messages on arquillian persistence api failure (because the logger is not working?).

Fagner Brack
  • 2,365
  • 4
  • 33
  • 69

3 Answers3

2

The message you are seeing is a warning, not an error. It means SLF4J is selecting a binding for you because you've not chosen one yourself. The default binding simply discards all log messages, which is not very useful.

If you have conflicting versions in Maven, normally it's safer to force the newer version. Libraries are often backwards compatible.

So, stick with your newer version of slf4j-api and just ensure you declare a binding as a dependency, e.g. slf4j-jdk14. If you are producing a library, ensure your binding is declared with test scope only.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • I have `slf4j-api 1.6.1` in one library and `slf4j-jdk14 1.5.6` in another library. Both required at compile scope. This is not a library production but a regular j2ee app ao I can't edit the original dependencies (or if it is possible how would I do it?). Should I make an exclusion of the old library and add the binding dependency outside the library dependency then? – Fagner Brack Feb 24 '13 at 18:45
  • 1
    @FagnerBrack Declare your preferred `slf4j-api` version in your POM - this will override all others. If you don't want `slf4j-jdk14`, then add an exclusion in the library that includes it. If you want it, but a different version, just declare your preferred version in your POM. – Duncan Jones Feb 24 '13 at 20:13
  • @FagnerBrack If you need further help, edit the question to share the relevant part of your POM file and include the output of `mvn dependency:tree`. – Duncan Jones Feb 24 '13 at 20:14
  • I added the slf4j-jdk14 1.6.1 and the problem has been solved. Maven have overwritten the old 1.5.6 version. – Fagner Brack Mar 03 '13 at 22:52
2

First of all. Regarding the dependencies.

In order to add SLF4J you must put ONE and only ONE of these dependencies in your pom.xml. It depends on what implementation you choose to use. Every dependency you add in the pom.xml is added automatically in the classpath. If one of the below dependencies are provided by another dependency then you can omit it. Dont forget that you must include only one even if the dependency is provided by another dependency.

<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>log4j-over-slf4j</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-jdk14</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>

Now regarding the annoying error you are getting when building your maven project. If after having only one of the above dependencies you still get the SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". then you are facing a bug from m2e.

Eclipse Juno and Indigo, when using the bundled maven version(m2e), are not suppressing the message SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behaviour is present from the m2e version 1.1.0.20120530-0009 and onwards.

Although, this is indicated as an error your logs will be saved normally. The highlighted error will still be present until there is a fix of this bug. More about this in the m2e support site.

The current available solution is to use an external maven version rather than the bundled version of Eclipse. You can find about this solution and more details regarding this bug in the question below which i think describes the same problem you are facing.

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

Community
  • 1
  • 1
Konstantinos Margaritis
  • 3,237
  • 3
  • 22
  • 32
0

JBoss 7.1 has built-in support for SLF4J. Assuming this is a web application with WAR packaging you add src/main/webapp/WEB-INF/jboss-deployment-structure.xml:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
  <deployment>
    <dependencies>
      <module name="org.slf4j" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

This will pull in the JBoss SL4J adapter which will give you logging output.

This implies that you want to use the application server provided libraries for SLF4J. You ought to update your pom.xml to fix the scope of the SLF4J dependency.

<dependencies>
  ...
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <scope>provided</scope>
  </dependency>
  ...
</dependencies>

Depending on how your POM file is arranged you may also need to give the version of SLF4J you want to use. mvn dependency:tree can show you which SLF4J deps are being pulled in. Make sure they are all getting the "provided" scope. If you use Eclipse and the m2e plugin you can also open your POM file and check the "Dependency Hierarchy" tab which will provide you with similar information.

Mark Jentz
  • 161
  • 6
  • Should I ignore all slf4j dependencies from maven libraries or this configuration will overwrite everything? – Fagner Brack Feb 26 '13 at 14:03
  • Using this configuration implies that you want your SLF4J stuff to be provided by the application server. I would recommend setting the scope to "provided". This way the SLF4J stuff will not be packed into your WAR file. JBoss will be instructed to pull it into the classpath from its modules, instead. If you use the `mvn dependency:tree` plugin you can see what is being pulled in and which scope it was, as @Duncan Jones suggested. If you declare `slf4j-api` in your pom and use the provided scope it will override the scope declared in querydsl. – Mark Jentz Feb 27 '13 at 08:45