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

vpitts

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">

    <modelVersion>4.0.0</modelVersion>

 

    <parent>

        <artifactId>platform-logger</artifactId>

        <groupId>com.tfsm.platform</groupId>

        <version>0.0.1-SNAPSHOT</version>

    </parent>

 

    <groupId>com.tfsm.platform</groupId>

    <artifactId>logger-service</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <packaging>bundle</packaging>

 

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

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

 

 

    <build>

        <plugins>

            <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-bundle-plugin</artifactId>

                <version>2.3.7</version>

                <extensions>true</extensions>

                <configuration>

                    <instructions>

                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>

                        <Bundle-Version>${project.version}</Bundle-Version>

                        <Export-Package>

                           com.tfsm.platform.logger*;version=${project.version}

                        </Export-Package>

                        <Import-Package>

                           javax.ws.rs;version="[1.1,2)",

                           javax.ws.rs.core;version="[1.1,2)",

                           org.aopalliance.intercept,

                           org.apache.cxf.jaxrs.ext,

                           org.apache.cxf.jaxrs.model,

                           org.apache.cxf.message,

                           org.apache.log4j,

                           org.apache.log4j.spi,

                           org.osgi.service.blueprint;version="[1.0.0,2.0.0)"

                        </Import-Package>

                    </instructions>

                </configuration>

            </plugin>

                     <plugin>

                           <groupId>org.apache.maven.plugins</groupId>

                           <artifactId>maven-compiler-plugin</artifactId>

                           <version>2.3.2</version>

                           <configuration>

                                  <source>1.6</source>

                                  <target>1.6</target>

                           </configuration>

                     </plugin>

        </plugins>

    </build>

 

    <dependencies>

       <dependency>

              <groupId>org.apache.cxf</groupId>

              <artifactId>cxf-rt-frontend-jaxrs</artifactId>

              <version>2.5.0</version>

       </dependency>

       <dependency>

              <groupId>aopalliance</groupId>

              <artifactId>aopalliance</artifactId>

              <version>1.0</version>

       </dependency>

       <dependency>

              <groupId>log4j</groupId>

              <artifactId>log4j</artifactId>

              <version>1.2.16</version>

              <scope>provided</scope>

       </dependency>

    </dependencies>

</project>

-----------------------------------------------------------------------------------------------------------------------

 

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

s.rs.core";version="0.0.1.SNAPSHOT",com.tfsm.platform.logger.intercepto

rs;uses:="org.apache.cxf.jaxrs.ext,org.apache.cxf.jaxrs.model,org.apach

e.cxf.message,javax.ws.rs.core,org.aopalliance.intercept,com.tfsm.platf

orm.logger";version="0.0.1.SNAPSHOT",com.tfsm.platform.logger;uses:="or

g.apache.log4j";version="0.0.1.SNAPSHOT"

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

[1.1,2)",org.aopalliance.intercept,org.apache.cxf.jaxrs.ext,org.apache.

cxf.jaxrs.model,org.apache.cxf.message,org.apache.log4j,org.apache.log4

j.spi,org.osgi.service.blueprint;version="[1.0.0,2.0.0)"

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.

 

VIKKI PITTS
Senior Software Engineer

17609 Ventura BLVD #300
encino, CA 91316
T 1.818.986.9047

[hidden email]
www.247media.com
a wpp company

 

 

Loading...