5 Replies Latest reply on Jun 5, 2012 10:33 AM by mathieuj

    ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout

    simplex-software

      Hi,

       

      The mentioned exception appears while trying to integrate a third-party application to run into Karaf 2.2.2 runtime on ServiceMix 4.4.1-fuse-03-06. The application relies of log4j being available in the runtime. Looking in the karaf documentation, it seems that this is the case, based on the following:

       

      In addition to being a standard OSGi Log service, it supports the following APIs:

       

          Apache Commons Logging

          SLF4J

          Apache Log4j

          Java Util Logging

       

      What could be the problem here ?

       

      Many thanks in adavance.

       

      Nicolas

        • 1. Re: ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout
          gertv

          L.S.,

           

           

          Pax Logging does expose the API for those logging systems, but it only exposes the bits required to do logging from your own application.  The Layout is a LOG4J specific interface to reconfigure the way the logger writes log entries, which is only useful if the actual implementation of the Logger interface is Log4J as well.

           

          Do you know what the third party library is trying to do when it is accessing this class? 

           

          It is possible in ServiceMix 4.4.1 to define custom layouts, appenders, ... but you would have to create a bundle fragment and attach that to the pax-logging-service bundle for the Pax Logging implementation to be able to access the layouts/appenders/...

           

           

          Regards,

           

          Gert Vanthienen

          • 2. Re: ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout
            simplex-software

            Hi Gert,

             

            Many thanks for your answer. The 3rd party application defines a class named org.pentaho.di.core.logging.LogWriter in which it obviously manipulates layouts.

             

            As a complementary information, here is an excerpt from the Karaf log file:

             

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

                    at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:845)

                    at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:74)

                    at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1839)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

                    at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:703)

                    at org.apache.felix.framework.resolver.WireImpl.getClass(WireImpl.java:102)

                    at org.apache.felix.framework.ModuleImpl.searchImports(ModuleImpl.java:1458)

                    at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:780)

                    at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:74)

                    at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1839)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

             

            My understanding is that the Apache log4j is not entirelly installed in Karaf despite the following command:

             

            karaf@root> packages:exports | grep log4j

                 3 org.apache.log4j; version=1.2.15

                 3 org.apache.log4j.spi; version=1.2.15

                 3 org.apache.log4j.xml; version=1.2.15

             

            Installing it should solve the problem, is that correct ? However, I wrapped the jar with the bnd utility and install it but this didn't change anything. So what should I do such that to have the Apche LOG4J entirelly installed, including the org.apache.log4j.Layout class ?

             

            Kind regards,

             

            Nicolas

            • 3. Re: ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout
              gertv

              Nicolas,

               

               

              I would be very hesitant to install log4j directly in the container, because there's a significant risk that other bundles too will start using your log4j bundle instead of using Pax Logging's API.  If that happens, those bundles no longer leverage the centralized configuration for all logging and they are also missing all the OSGi specific improvements that were added to the logging.

               

              If possible, I would try to extract the LogWriter class in a separate fragment and attach to the pax-logging-service bundle, allowing you to configure/setup the LogWriter through the Pax Logging configuration files so it becomes part of the existing logging system.  Not sure that is really possible, it will depend on how/where the LogWriter is being set up.

               

              Another (probably simpler) option would be to embed log4j in your application entirely and not export/import the log4j packages from your application at all, so that the extra log4j classes are only visible to your own application bundle and not to all the other bundles in the container.

               

               

              Regards,

               

              Gert Vanthienen

              • 4. Re: ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout
                simplex-software

                Hi Gert,

                 

                Many thanks again. Yeah, it seems too complicated and not a good idea. I'll drop it.

                 

                Kind regards,

                 

                Nicolas

                • 5. Re: ServiceMix 4.4.1 - java.lang.NoClassDefFoundError: org/apache/log4j/Layout
                  mathieuj

                  I'm using serviceMix 4.4.1 too, and i have a warnimg which look like this problem.

                   

                  when i launch my bundle, fuse answer that:

                   

                  Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@1f2182c, cause: org/apache/log4j/LogManager

                   

                  but the bundle is correctly launch.

                   

                  how i could do for resolve this warnimg.

                   

                  thank you