Thursday, March 29, 2012

Optimal Java EE Webapp Logging Configuration for JBoss AS7 Deployment

I used to configure logging (via SLF4J) in my Java EE web applications like this:

<properties>
    <slf4j.version>1.6.4</slf4j.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
    </dependency>
</dependencies>

Although in practice this works well, it's not efficient because I'm bundling my own SLF4J libraries with my webapp, and direct them to JDK Logging, which is handled properly by JBoss AS 7.1.

Note that there's nothing wrong with the above configuration, because makes the webapp very portable across Application Servers (even servlet containers like Tomcat).

Thanks to Joshua Davis, I got the perfect logging configuration for JBoss AS7:

<properties>        <slf4j.version>1.6.4</slf4j.version></properties>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.1.1</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

<version>${slf4j.version}</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>jcl-over-slf4j</artifactId>

<version>${slf4j.version}</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-jdk14</artifactId>

<version>${slf4j.version}</version>

<scope>provided</scope>

</dependency>

</dependencies>

</dependencyManagement>

Dependencies:

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>jcl-over-slf4j</artifactId>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-jdk14</artifactId>

</dependency>


Since SLF4J is already defined as a JBoss 'module', then all that we need to do is to reference the module from the WAR file.1 The simplest way is to get Maven to list the dependency in META-INF/MANIFEST.MF:

<plugin>

  <groupId>org.apache.maven.plugins</groupId>

  <artifactId>maven-war-plugin</artifactId>

  <version>2.2</version>

  <configuration>

    <archive>

      <manifestEntries>

        <Dependencies>org.slf4j, org.apache.commons.logging</Dependencies>

      </manifestEntries>

    </archive>

  </configuration>

</plugin>

This will generate a META-INF/MANIFEST.MF file that has this line in it:

Dependencies: org.slf4j, org.apache.commons.logging


This tweak saves space, RAM, and probably increases webapp performance a bit too. :-)


To learn more about Java Web Development using Java EE 6, I highly recommend The Java EE 6 Tutorial: Basic Concepts (4th Edition) (Java Series) by Eric Jendrock, Ian Evans, Devika Gollapudi and Kim Haase.

13 comments:

Anonymous said...

This article has me looking from the past and only now I found it. Improve the quality of your articles and continue to create a more interesting.thecertifiedflooring.com |

homes-products.com |

roof-removals.com |

homeimprovement4sure.com |

homeimprovement-inn.com |

home-improvement-cast.com |

home-improvement-tv.com |

houseimprovement4sure.com |

alfa-dogs.com |

catsforreal.com |

dogstrike.com |

hotdogs-creteil.com |

guide2coach.com |

golfspotinlondon.com |

arnold-sports-festival.com |

coach outlet store online said...

http://www.coachoutletstoreinc.com/ Coach Outlet Store Online

http://www.michaelkorsoutletmkinc.com/ Michael Kors Outlet

http://www.coachfactoryoutletwebsite.com/ Coach Factory Outlet

http://www.tomsusashoes.com/ Toms Shoes

http://www.cheapjerseysinc.com/ Cheap Jerseys

http://www.michaelkors-bedford.com/ Michael Kors

http://www.coachoutlet-sale.com/ Coach Outlet

http://www.coachfactoryoutletorg.com/ Coach Factory Outlet

http://www.coachoutlet-buy.com/ Coach Outlet

http://www.coachhandbagsonlineoutlet.com/ Coach Handbags

http://www.giuseppezanottionline.com/ Giuseppe Zanotti

http://www.coachfactoryoutlet-handbags.com/ Coach Factory Outlet

http://www.coach-factory-outlet-online.com/ Coach Factory Outlet Online

http://www.coachstoreonline.com/ Coach Outet Store Online

http://www.coachfactoryoutlets2014.com/ Coach Factory Outlet

http://www.michaelkorsoutletonlinemk.com/ Michael Kors Outlet Online

http://www.celineoutlet-online.com/ Celine Outlet

http://www.michaelkors.name/ Michael Kors

http://www.michael-kors-outlet-store.com/ Michael Kors Store

http://www.tomsshoescompany.com/ Tomss Hoes

http://www.pradaoutlet-store.com/ Prada Outlet

http://www.fitflopfootwear.com/ Fitflop Footwear

http://www.celinebags-outlet.com/ Celine Bags

http://www.fitflopsflipflops.com/ Fitflops Flipflops

http://www.fitflopusaonline.com/ Fitflops

http://www.giuseppezanottidesigner.com/ Giuseppe Zanotti Designer

http://www.fitflopflip-flop.com/ Fitflops

http://www.giuseppezanottisneakersmen.com/ Giuseppe Zanotti Sneakersmen

http://www.fitflopsandalssale.com/ Fitflops

jhoney said...

You can't really say what is beautiful about a place, but the image of the place will remain vividly with you.
http://businessideagroup.com|http://americanhealthstar.com|http://pamparedpets.com|http://dianasazpetsitting.com|http://cotton-house-hotel.com

Garage Door Repair Houston said...

The love of beauty in its multiple forms is the noblest gift of the human cerebrum.

Double Glazing Preston said...

You can only perceive real beauty in a person as they get older.

Roller Shutters said...

We are learning, too, that the love of beauty is one of Nature's greatest healers.

Rikudou4rt said...

thanks you

AnonymousJeffers said...

An interesting read for all. The piece is an expression and one which will most proably generate mixed opinions. Good work from our perspective. Affordable SEO Services in Manchester

Anonymous said...

A good illustrated post that is well written and presented well. If you need any help feel free to contact us. CGO Media - SEO Manchester

Sundar Kurya said...

it's a very informative article
funny videos
technology

YASIR MEHMOOD said...

pcsoftware

fitflop uk said...

After basically michael kors outlet out her coach factory assets tiffany and co jewelery in a low-coach factory blazer ensemble, the michael kors outlet reality coach outlet star louis vuitton handbags showed louis vuitton outlet off her coach factory outlet curves in ray ban sunglasses a see-tory burch outlet lace michael kors outlet this oakley sunglasses cheap week. But coach factory outlet worry, she coach store online bra this valentino time. I love coach outlet the louis vuitton outlet minimalist air jordan aesthetic true religion jeans brought to coach factory. He cheap ray ban sunglasses knows that timberland shoes because tory burch spending top prada outlet doesn't true religion outlet mean you coach factory outlet extra coach outlet store online bells <a href="http://www.officialcoachfactoryoutlet.com/"

Obat pembesar penis said...

thanks for the information given
This information is very useful for me to be a reference
once again thank you for sharing with us all
alat sex wanita
alat sex pria
alat bantu wanita
alat bantu pria
boneka sex
obat perontok bulu
obat pembesar penis
vimax
obat kuat
vimax asli
vimax
cara merontokan bulu ketiak
obat pelangsing alami
obat penggemuk badan
obat peninggi badan
cream pembesar payudara
obat pembesar payudara
alat pembesar payudara
obat ejakulasi dini
alat pembesar penis
obat perangsang wanita
perangsang wanita

Post a Comment

 
Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan