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.

6 comments:

  1. Hi Michał,

    Nice blog! Is there an email address I can contact you in private??

    ReplyDelete
  2. Hi Ilias, sure, there it is: http://m1key.me/about_me/

    ReplyDelete
  3. A prefered way is to use the jboss-deployment-structure.xml file.
    Here is an example:

    ReplyDelete
    Replies
    1. http://pastebin.com/69PAdp7S

      Delete
  4. Hi Akram, I'm afraid you're going to have to escape the xml code ([blah][/blah]) or provide a link, sorry.

    ReplyDelete
  5. Using SLF4J with JBoss AS7 is a smart choice for effective logging management! It simplifies the process Prevention of Domestic Violence Act New Jersey||Domestic Violence Lawyer New Jersey and enhances flexibility in tracking application performance. A great way to ensure robust and clean log handling!

    ReplyDelete