Antonio Petricca Antonio Petricca - 29 days ago 3x
Java Question

maven-archetype-j2ee-simple archetype logging module

I have a trouble understanding the


Does anybody know how to use the logging module inside a maven project?

Have I to configure log4j inside it? If yes, how?

Thank you,


The log4j use has nothing to use with the maven-archetype-j2ee-simple archetype. As you have generated your project following this archetype, I assume you hit many modules in the parent project:

 \_ ears
 |_ ejbs
 |_ servlets
 |_ primary-sources
 |_ ...

This skeleton is the one a Java Enterprise application should have as it contains some EJBs which goes on the ejbs module and that hold the main service logic for the application along with a primary-sources project that should underlie additonnal sources and classes used in the application. There is also a servlets module which will hold Servlets as the main entry for your web application.

If you want to have your logging configuration setup in place and using the apache log4j implementation just follow a simple tutorial on how to do that.

As a simple roadway I can think of is to have, the log4j dependency in the parent pom.xml descriptor so you can use the logging API in all your modules and this is straightforward and simple from developer point. But at runtime you should have a Servlet with an init() method to be called as your application starts and which will initialize the log4j configuration since this is not done implicitelly and needs some customization. (As you may have a holding your configuration if you don't want to go with te BasicConfigurator).