I'm using logback in an EAR-File which contains a JAR (ejb) and a WAR. This should run on a Glassfish v3 Server. Everything works, except the loading of the logback.xml. This can't be found. I build the Project with Netbeans. The used external libs are in the lib-Directory of the EAR (Which shouldn't make a difference where they are...). I've planed to put the logback.xml-File in the root-Directory or another Subdirectory in the EAR. The Classpath is set in the Manifest-Files of the JAR and WAR. But for some Reasons the logback.xml wasn't found... (The build ear contains the logback.xml ;) )
I've tryied every location of the logback.xml. Even in the WAR or JAR. Nothing worked...
If I use a standalone WAR then everything works fine and the logback.xml was found. (OK. Not everything. Changing the Classpath in the Manifest doesn't work...)
So my Question: Has anybody already get logback.xml to run within an EAR?
Here is my Manifest (I hope, that this ist the correct Syntax):
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0_147-icedtea-b147 (Oracle Corporation)
Class-Path: ./
Hope someone can help me.
Regards
I solved this problem creating a separated simple jar that I deploy exploded inside the EAR (using Maven and a separated module config.jar). In practice, the logback.xml was inserted in lib/config.jar/logback.xml
I've found out a solution without putting another jar in the classpath. 1) Just put the logback.xml into the classpath of the war application (/src/java/ for instance); 2) Use a ServletContextListener to load the file using getResourceAsStream and, eventually, set some parameters (like the application name) as in the snipped below:
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Logback contextInitialized !!!!");
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context); context.reset();
// override default configuration
// inject the name of the current application as "application-name"
// property of the LoggerContext
context.putProperty("application-name", "menu_dinamico");
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("logback.xml");
if(is == null) {
System.out.println("Logback xml file non trovato");
}
else {
jc.doConfigure(is);
}
} catch (JoranException ex) {
System.out.println("Logback contextInitialized error");
StatusPrinter.print(context);
ex.printStackTrace();
}
}
Now the file logback.xml is recognized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With