Glassfish 3 + ear + logback.xml

I use logback in an EAR file that contains JAR (ejb) and WAR. This should run on the Glassfish v3 server. Everything works, except for loading logback.xml. It is impossible to find. I am creating a project with Netbeans. The external libraries used are located in the lib-Directory EAR (which should not matter where they are ...). I planned to put the logback.xml file in the root directory or another subdirectory in the EAR. The Classpath is specified in the JAR and WAR manifest files. But for some reason, logback.xml was not found ... (Courting the assembly contains logback.xml;))

I tried every place in the logback.xml file. Even in WAR or JAR. Nothing worked ...

If I use a standalone WAR then everything works fine and logback.xml was found. (OK. Not all. Changing the class path in the manifest does not work ...)

So my question is: Does anyone already run logback.xml to run in the EAR?

Here is my manifest (I hope this is 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.

Hi

+4
jsf glassfish logback ear
source share
2 answers

I solved this problem by creating a separate simple jar that I am deploying to explode inside the EAR (using Maven and a separate config.jar module). In practice, logback.xml has been inserted into lib / config.jar / logback.xml

+4
source share

I found a solution without putting another jar in the classpath. 1) Just put the logback.xml file in the class path of the military application (/ src / java / for example); 2) Use ServletContextListener to load the file using getResourceAsStream and, ultimately, set some parameters (for example, the name of the application), as shown 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 logback.xml file is recognized.

+2
source share

All Articles