1

This thread solve my problem in WAR (JSF 2) project, but when project is EAR this solution dont work.

Logback and Jboss 7 - don't work together?

I am using JBOSS 7.1.

UPDATE:

I create a new JSF project in eclipse (JBoss Tools and JBOSS 7.1 runtime). Add the jars slf4j-api-1.7.5.jar, logback-core-1.0.13.jar, logback-classic-1.0.13.jar and logback-access-1.0.13.jar.

this code in bean:

@Named
public class BeanTeste {

private Logger log = LoggerFactory.getLogger(BeanTeste.class);

public void executar(){
log.debug("TESTE DE DEBUG");
log.info("TESTE DE INFO");
log.warn("TESTE DE WARN");

// print internal state
   LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
   StatusPrinter.print(lc);

System.out.println("METODO COMPLETADO!");
}

should return:

18:00:09,278 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.274 [http--0.0.0.0-8080-1] DEBUG com.br.teste.BeanTeste - TESTE DE DEBUG

18:00:09,280 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.279 [http--0.0.0.0-8080-1] INFO  com.br.teste.BeanTeste - TESTE DE INFO

18:00:09,282 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.282 [http--0.0.0.0-8080-1] WARN  com.br.teste.BeanTeste - TESTE DE WARN

18:00:09,284 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,223 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]

18:00:09,286 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

18:00:09,288 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]

18:00:09,291 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,225 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.

18:00:09,293 INFO  [stdout] (http--0.0.0.0-8080-1) 

18:00:09,293 INFO  [stdout] (http--0.0.0.0-8080-1) METODO COMPLETADO!

but return

Exception starting filter WicketFilter: java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to ch.qos.logback.classic.LoggerContext

in a WAR project, I create a jboss-deployment-structure.xml file and place it in WEB-INF directory and solved my problem.

<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies     -->
        <exclusions>
            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

When the WAR project is add a EAR project the problem returns.

any ideas?

Community
  • 1
  • 1
Alberto Rocha
  • 21
  • 1
  • 4
  • Why this solution doesn't work for you? What's going on? – Math Sep 27 '13 at 17:47
  • when the project is simple WAR, put the file jboss-deployment-structure.xml in WEB-INF directory resolves the error: Exception starting filter WicketFilter: java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to ch.qos.logback.classic.LoggerContext. But when the WAR project is EAR project this error persist – Alberto Rocha Sep 27 '13 at 18:01
  • It would be great if you could add those informations in your question. Without any formatting is a kind of hard to understand. This act may encourage people to read your question and answer to it. It would be even better if you post the piece of the code you think that needs adjustments. – Math Sep 27 '13 at 18:08
  • Duplicate logback jars have been loaded by different class loaders. Remove the duplicates to resolve the issue. – DwB Sep 27 '13 at 18:53
  • I searched some but have not found duplicate jar. Maybe being loaded by JBOSS. In this case how to find out? – Alberto Rocha Oct 01 '13 at 13:55

1 Answers1

0

I changed my jboss-deployment-structure.xml with the content below and it worked.

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
    <dependencies>
    </dependencies>
</deployment>
<sub-deployment name="Teste.war">
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
</sub-deployment>
<sub-deployment name="TesteEJB.jar">
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
</sub-deployment>

thanks a lot!!!!

Alberto Rocha
  • 21
  • 1
  • 4