2011-11-20

Use SLF4J with JBoss AS7

SLF4J is a module in JBoss AS7. I therefore assumed it would not be necessary to ship SLF4J with my web application. To my surprise, my application failed with a ClassNotFoundException.
Caused by:
java.lang.ClassNotFoundException:
org.slf4j.Logger
Hmm... How can I use a JBoss AS7 module as a dependency? The solution is to add the org.slf4j entry as a MANIFEST.MF dependency. The MANIFEST.MF file looks then like that:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: M1key
Build-Jdk: 1.6.0_27
Dependencies: org.slf4j
Maven can do it for you automatically.
<plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-war-plugin</artifactId>
               <configuration>
                   <archive>
                       <manifestEntries>
                           <Dependencies>org.slf4j</Dependencies>
                       </manifestEntries>
                   </archive>
               </configuration>
           </plugin>
I guess I should have RTFM... More about class loading in AS7.