开发者

Getting no class def found error. Log4J -> Java

开发者 https://www.devze.com 2023-01-01 18:06 出处:网络
I created a simple web application and added log4J\'s jar in my lib folder and it seems to work fine. Then i created a Ejb module and did the same thing of adding jar file in my classpath, but i am ge

I created a simple web application and added log4J's jar in my lib folder and it seems to work fine. Then i created a Ejb module and did the same thing of adding jar file in my classpath, but i am getting this error :-

Caused by: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
        at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:4929)
        at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4761)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
        ... 94 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
        at common.Utils.getRssFeed(Utils.java:128)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
        at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
        at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5243)
        at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbIn开发者_Go百科vocation.java:615)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
        at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
        at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
        at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
        at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5215)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
        ... 92 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
        at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:736)
        at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:626)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 113 more

I don't even have any other version of log4j in classpath. Any idea why is this error coming?

Actually first i created a Enterprise application and everything seemed to work fine. But then, i copied files from my enterprise application's ejb module to a separate module and since then these errors are coming. This is in my build-impl.xml :-

<target depends="compile" name="library-inclusion-in-archive">
        <copyfiles files="${libs.Log4J.classpath}" todir="${build.classes.dir}"/>
    </target>
    <target depends="compile" name="library-inclusion-in-manifest">
        <copyfiles files="${libs.Log4J.classpath}" todir="${dist.ear.dir}/lib"/>
        <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
    </target>

Don't know why is this pointing to ear instead of jar. Is there any problem with the above statement? How do i resolve this? I am using Netbeans 6.8

Thanks in advance :)

EDIT :-

The structure of my ejb module is :-

   mymodule.jar
    |_mypackage
    | |_myclass.class
    |
    |_META_INF
    | |_MANIFEST.MF
    | |_persistence.xml
    | |_sun-ejb-jar.xml
    |
    |_log4j-1.2.16.jar

The contents of my MANIFEST.MF is :-

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.7.1

Created-By: 14.1-b02 (Sun Microsystems Inc.)

Class-Path: log4j-1.2.16.jar

There is no application.xml

2nd Edit If i place lib file in my appserver/lib directory, it works fine. Why can't i make use of external jar files from within my project?


Honestly, it's hard to say from your actual description of the problem (what did you exactly, what is the current structure of your application, what class path are you referring to, etc). But my understanding is that your ear should look like this:

myear.ear
|-- lib
|   `-- log4j.jar
|-- META-INF
|   |-- application.xml
|   `-- MANIFEST.MF
|-- mywebapp.war
`-- myejbs.jar

And the MANIFEST.MF should contain an entry like this:

Class-Path: myejbs.jar lib/log4j.jar

Double check that you have something similar. If you do, please update your question with the structure of your ear, your MANIFEST.MF, your application.xml.


EJBs don't have an equivalent of WEB-INF/lib and while packaging libraries inside an ejb-jar might work with some application server, or not, this is not part of the JAR specification and does not comply with Sun's standards regarding J2EE packaging. So to my knowledge, an EJB and the JARs it depends on should be packaged in an EAR.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号