找不到类定义错误. Log4J->爪哇 [英] Getting no class def found error. Log4J -> Java

查看:91
本文介绍了找不到类定义错误. Log4J->爪哇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的Web应用程序,并在我的lib文件夹中添加了log4J的jar,它似乎可以正常工作.然后我创建了一个Ejb模块,并做了同样的事情在我的类路径中添加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

我什至在classpath中甚至没有其他版本的log4j.知道为什么会出现此错误吗?

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

实际上,首先我创建了一个Enterprise应用程序,并且一切正常.但是随后,我将文件从企业应用程序的ejb模块复制到了一个单独的模块,此后便出现了这些错误.这是在我的build-impl.xml中:-

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>

不知道为什么它指向耳朵而不是罐子.上面的陈述有什么问题吗?我该如何解决?我正在使用Netbeans 6.8

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

先谢谢您了:)

-

我的ejb模块的结构是:-

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

我的MANIFEST.MF的内容是:-

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

没有application.xml

第二次修改 如果我将lib文件放在我的appserver/lib目录中,则可以正常工作.为什么我不能在项目中使用外部jar文件?

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

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

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

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

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

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.

EJB没有WEB-INF/lib的等效项,尽管在ejb-jar中打包库可能与某些应用程序服务器一起工作,但不是,这不是

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.

这篇关于找不到类定义错误. Log4J-&gt;爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆