title: Karaf bundle can not find Log4j LogManager.class in the run time.
body: <p>Currently I am working on a project which I need to wave third party JAR into our Karaf D-OSGi application.   We aren't suppose to change any code inside the jar, but with limited source code we can debug into it.</p>
  
  <p>The issue is that the third party jar depends on log4j-1.2.9 jar.   however when the third party jar was called in the running time ,  logManager.class can not be found from the third party jar. </p>
  
  <h2>here is the exception logs from Karaf.</h2>
  
  <pre><code>karaf@root()&gt; lde
  </code></pre>
  
  <p>org.apache.cxf.interceptor.Fault: org/apache/log4j/LogManager
          at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)[166:org.apache.cxf.cxf-core:3.1.7]
          at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)[166:org.apache.cxf.cxf-core:3.1.7]
          ...
  org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[115:org.eclipse.jetty.util:9.2.19.v20160908]
          at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[115:org.eclipse.jetty.util:9.2.19.v20160908]
          at java.lang.Thread.run(Thread.java:745)[:1.8.0_25]
  Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/LogManager
          at com.p*******h.eis.tools.logging.LoggingSetup.isConfigured(LoggingSetup.java:77)
          at com.p*******h.o****l.sdk.configurator.Configurator.checkLogging(Configurator.java:623) (------------inside the third party jar------------------)
          at com.p*******h.o****l.sdk.configurator.Configurator.load(Configurator.java:383)
          at com.p*******h.o****l.sdk.configurator.Configurator.getInstance(Configurator.java:72)
          at com.p*******h.o****l.sdk.transactionProcessor.TransactionProcessor.(TransactionProcessor.java:43)
          at ca.esc.pbm.integr.chase.provider.service.PbmChaseApiImpl.getCCtokenFromChasePaymentGateWay(PbmChaseApiImpl.java:98)</p>
  
  <pre><code>    ... 36 more
  </code></pre>
  
  <p>Caused by: java.lang.ClassNotFoundException: org.apache.log4j.LogManager not found by org.ops4j.pax.logging.pax-logging-api [1]
          at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
          at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
          ...
          ... 50 more</p>
  
  <h2>karaf@root()></h2>
  
  <p>in the bundle ,  pom.xml has log4j 1.2.8 dependency.
   and in bnd.bnd,      Export-Package :  org.apache.log4j.*,  .....</p>
  
  <hr>
  
  <p>I have checked the generated bundle jar from maven, log4j package/jar was imported into the bundle and in the Karaf run time.</p>
  
  <p>I did some debugging/research , looked like Pax logger take over/delegate the Log4j which hide the LogManager from the bundle.</p>
  
  <hr>
  
  <p>Plus, I tried to call LogManager from the bundle directly without involving the third party Jar, I get the same exception that LogManager.class can not be found. </p>
  
  <p>I understand Karaf use Pax logger for logging and delegate log4j implementation to Pax, however in my case how can I let the untouchable Jar class calling the LogManager successfully?</p>
  
  <p>Thanks</p>
  
  <p>Paul N.</p>