log4j and Karaf 3.0.0.RC - java.lang.NoClassDefFoundError: org/apache/log4j/Layout

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

log4j and Karaf 3.0.0.RC - java.lang.NoClassDefFoundError: org/apache/log4j/Layout


I am hoping someone out there can help me with this problem that has plagued me for the past two weeks.  Admittedly, I am somewhat new to OSGI and Karaf but I have spent the past month or so going through the Karaf tutorials and reading books and postings on this topic.  And I am beginning to think that there is a fundamental problem in trying to import org.apache.log4j package into my bundle.


I am trying to create and deploy a bundle for one of our group’s prototype projects for a logger service that is destined to become a part of a large cxf-based platform of services for our organization.  I started with a project that was built using the log4j libraries:  log4j-1.2.16.jar.


I can successfully install and start my bundle and it is listed in Karaf as “Active”.  (Note that I have also loaded the cxf and http features into Karaf before installing my features).  However, when I attempt to hit the url associated with my bundle to test the code, two things happen:

·         I do see successful trace statements in the Karaf command window that were produced using System.out.println – this demonstrates that part of the code is running and reaching certain points (this is good)

·         In the browser, I receive an HTTP Error 500:  java.lang.NoClassDefFoundError: org/apache/log4j/Layout

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

                at com.tfsm.platform.logger.ApiLoggerBean.setConfig(ApiLoggerBean.java:65)

When I investigate the code, there is no direct reference to org.apache.log4j.Layout.  However in an attempt to create and append a FileAppender to the log4j logger, we are passing an instance of a PatternLayout to the constructor for FileAppender; PatternLayout extends Layout.


I believe that my MANIFEST.MF file is correct in that it includes the appropriate Import-Package entries:


Here is the bundle’s maven pom.xml file


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">














    <name>logger-service Blueprint Bundle</name>

    <description>logger-service OSGi blueprint bundle project.</description>
































































Here is the resulting MANIFEST.MF file contents:

Manifest-Version: 1.0

Bnd-LastModified: 1374693788927

Build-Jdk: 1.7.0_21

Built-By: V.Pitts

Bundle-Description: logger-service OSGi blueprint bundle project.

Bundle-ManifestVersion: 2

Bundle-Name: logger-service Blueprint Bundle

Bundle-SymbolicName: logger-service

Bundle-Version: 0.0.1.SNAPSHOT

Created-By: Apache Maven Bundle Plugin

Export-Package: com.tfsm.platform.logger.test;uses:="javax.ws.rs,javax.w






Import-Package: javax.ws.rs;version="[1.1,2)",javax.ws.rs.core;version="




Tool: Bnd-1.50.0



Note: That the log4j jar file is listed as a Maven dependency for compilation purposes.  I did open this jar file using a de-compiler and saw that this bundle does in fact export org.apache.log4j.  Furthermore, when I try to solve the problem by simply copying the log4j jar file into the Karaf deploy directory, the jar file does not load.  I receive a BundleException:

org.osgi.framework.BundleException: Duplicate import: com.sun.jdmk.comm

                at org.apache.felix.framework.util.manifestparser.ManifestParser.normalizeImportClauses(ManifestParser.java:342)[org.apache.felix.framework-4.0.3.jar:]


So I am stuck.  What am I missing here?  Can we use log4j as the basis for our logger?  Is there some other step I need to take?


Thank you all in advance.


Senior Software Engineer

17609 Ventura BLVD #300
encino, CA 91316
T 1.818.986.9047

[hidden email]
a wpp company