没有找到类定义错误。 Log4J->爪哇

发布于 2024-09-03 09:52:29 字数 4441 浏览 0 评论 0原文

我创建了一个简单的 Web 应用程序,并将 log4J 的 jar 添加到我的 lib 文件夹中,它似乎工作正常。然后我创建了一个 Ejb 模块,并做了同样的事情,在我的类路径中添加 jar 文件,但我收到此错误:-

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(EjbInvocation.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

我什至在类路径中没有任何其他版本的 log4j。知道为什么会出现这个错误吗?

实际上,首先我创建了一个企业应用程序,一切似乎都工作正常。但是后来,我将文件从企业应用程序的 ejb 模块复制到一个单独的模块,从那时起这些错误就出现了。这是在我的 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>

不知道为什么 this 指向 Ear 而不是 jar。上述说法有问题吗?我该如何解决这个问题?我正在使用 Netbeans 6.8

提前致谢:)

编辑:-

我的 ejb 模块的结构是:-

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

我的 MANIFEST.MF 的内容是:-

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

没有 application.xml

<强>第二次编辑 如果我将 lib 文件放在 appserver/lib 目录中,它就可以正常工作。为什么我不能在我的项目中使用外部 jar 文件?

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(EjbInvocation.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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-09-10 09:52:29

老实说,从您对问题的实际描述中很难说出来(您到底做了什么,应用程序的当前结构是什么,您指的是哪个类路径等)。但我的理解是,你的耳朵应该看起来像这样:

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

并且 MANIFEST.MF 应该包含这样的条目:

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

仔细检查你是否有类似的东西。如果您这样做,请用您的耳朵结构、您的 MANIFEST.MF、您的 application.xml 更新您的问题。


EJB 没有相当于 WEB-INF/lib 的东西,虽然 ejb-jar 内的打包库可能适用于某些应用程序服务器,也可能不适用,但这不是 JAR 规范 并且不符合 Sun 关于 J2EE 打包。据我所知,EJB 及其依赖的 JAR 应该打包在 EAR 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文