3 Replies Latest reply on Jun 26, 2014 3:47 AM by jeff jeff

    NoClassDefFoundError: org/apache/log4j/Layout

    jeff jeff Newbie

      Hey !

       

      I have a problem with karaf (packaged in fuse esb version 6.1.0) I am in a camel / spring / maven / jboss fuse / karaf environnement

       

      I have a bundle which use log4j like this :

         [...]

         import org.apache.log4j.*;

         [...]

         Logger classlogger = Logger.getLogger("LoggerWrapper");

       

      In dev it works fine but when I run the bundle in the ESB, I have the error :

       

      [...]

      Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Layout

        at com.ericsson.mediation.core.bean.CoreLogger.log(CoreLogger.java:90)[265:MEDIATION-SI800-Core:1.0.0]

      [...]

      Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout not found by org.ops4j.pax.logging.pax-logging-api [4]

       

      I am in migration from jboss fuse esb 6.0.0 to 6.1.0 , with the previous version my bundle works fine but I have bundled and installed and OSGI version of log4j .

       

      I have found this topic : http://mail-archives.apache.org/mod_mbox/karaf-user/201309.mbox/%3C10791_1379436469_523887B5_10791_2213_1_C4E3C19CD10AA241A4A01199E95BAC4102CFBE2505@THSONEA01CMS05P.one.grp%3E

       

      Which talk about exactly the same problem but with no clear answer ( for me

       

      By the way it works when I use :

       

      [...]

      import org.slf4j.Logger;

      import org.slf4j.LoggerFactory;

      [...]

      private Logger LOG = LoggerFactory.getLogger(ROUTE.class);

      Any help would be really appreciated I deal with this problem since yesterday ...

      Thanks !

       

      JF

       

      ( I have already post a message in KARAF user nabble, I don't know wich on is the " good " forum.

        • 1. Re: NoClassDefFoundError: org/apache/log4j/Layout
          jeff jeff Newbie

          I have exclude log4j dependancy in my maven project and insert org.ops4j.pax.logging reference.

           

           

                   <dependency>

            <groupId>org.ops4j.pax.logging</groupId>

            <artifactId>pax-logging-api</artifactId>

            <version>1.7.2</version>

            </dependency>

           

            <dependency>

            <groupId>org.ops4j.pax.logging</groupId>

            <artifactId>pax-logging-service</artifactId>

            <version>1.7.2</version>

            </dependency>

           

           

           

           

          I see that the org.apache.log4j.Logger is not the same than the class in log4j dependancy ( missing removeAllAppenders / missing setLevel / ... ) that my project used.

          • 2. Re: NoClassDefFoundError: org/apache/log4j/Layout
            jeff jeff Newbie

            I have try to find a workaround with log4J, but nothing works, any idea ?

            • 3. Re: NoClassDefFoundError: org/apache/log4j/Layout
              jeff jeff Newbie

              I have identified more precisely what is wrong. With 2 simples use cases :

               

              1/ If I do :

               

              import org.apache.log4j.*;

               

              public void Log(String logname) {

                      Logger filelogger = Logger.getLogger(logname);

                      filelogger.info("HELLO");

              }

               

              ==> Everything is fine

               

              2/ If I do :

               

              public void Log(String logname) {

                      Logger filelogger = Logger.getLogger(logname);

                      filelogger.info("HELLO");

                      filelogger.removeAllAppenders();

              }

               

              ==> Aoutch

              Caused by: java.lang.NoSuchMethodError: org.apache.log4j.Logger.removeAllAppenders()V

                at com.ericsson.mediation.core.bean.LoggerWrapper.Log(LoggerWrapper.java:78)[265:XXXXXXXXXXX:1.0.0]

               

              I got the felling that in the karaf context, the org.apache.log4j.Logger is not the "real one" and indeed this is a lot of Logger class declared

              (via a find-class Logger)

               

               

              I would like to know if there is a way to tell to org.ops4j.pax.logging.pax-logging-XXX to use the " real " one ?

               

              Thanks for your help

               

              JF