意外异常:java.lang.NoClassDefFoundError:org / apache / log4j / LogManager [英] unexpected exception: java.lang.NoClassDefFoundError: org/apache/log4j/LogManager

查看:247
本文介绍了意外异常:java.lang.NoClassDefFoundError:org / apache / log4j / LogManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发GWT应用程序。它使用RPC从内部系统收集信息。它通过使用库jar来实现,让它称之为alpha.jar。我们在许多应用程序中使用这个jar,所以它工作正常,并且在eclipse之外使用ANT构建它。



alpha.jar中的一些类引用了LOG4J2,还有很多其他外部jar,所以当我们运行一个应用程序时,我们传递一个类路径给所有这些,一切都很好的。请注意,这不是一个简单的初学者问题。 alpha.jar正常工作,包括对Log4J的调用。



问题:



在Eclipse中,我有这个GWT应用程序项目,还有Alpha.jar项目(当然有源代码)。服务器部分需要调整Alpha对象并与Alpha系统进行通信。



在GWT中通过向Alpha项目添加构建路径引用来完成此工作,我的GWT应用程序运行正常。



当我代替项目引用包含(在war / WEB-INF / lib中)alpha.jar并运行应用程序时,我收到错误在第一次我从alpha.jar实例化一个课程。



alpha.jar的构建方式没有什么特别之处,所以基本上应该是一样的作为eclipse中的项目,对吗?



请注意以下事项:



*)alpha.jar的依赖罐子也在战争/ WEB-INF / lib。 log4j2-core,log4j-api以及其他一些(例如apache)



*)如果我删除alpha.jar(和调用的代码它),而只是添加代码,称为LOG4J2,该代码也工作正常!



使用JAR时如何得到这个奇怪的错误?还要注意NoClassDefFoundError,它不是更常见的ClassNotFoundException。请参阅什么原因和NoClassDefFoundError与ClassNotFoundException之间的区别?



如果您需要更多信息让我知道。

解决方案

org.apache.log4j.LogManager 是一个来自log4j 1.2(不是log4j2)的类。



因此,一个您的网络应用程序jar必须引用它。歹徒应该在堆栈跟踪中可见。



根据您的具体情况,您可能需要在Web应用程序中添加一个log4j 1.2 jar,因为两个版本完全是彼此独立。


I'm developing a GWT application. It's using RPC to collect information from an internal system. It does so by using a library jar, lets call it alpha.jar. We are using this jar in many application so it works fine, and btw its built with ANT, outside eclipse.

Some classes in alpha.jar references LOG4J2 and also lots of other external jars, so when we run an application we pass a classpath to all those, and everything works out fine. Please note that this is not a simple beginners problem. The alpha.jar is working as it should, including calls to Log4J.

The problem:

In Eclipse, I have this GWT application project and also the Alpha.jar project (with source code of course). The server part needs to instatiate alpha objects and communicate to the alpha system.

When do this in GWT by adding a build-path-reference to the Alpha project, my GWT app runs fine.

When I instead of the project reference include (in war/WEB-INF/lib) the alpha.jar and runs the app, I get the error in the title the first time I instantiate a class from alpha.jar.

There are no peculiarities in how the alpha.jar is built, so basically it should be the same thing as the project in eclipse, right?

Note the following:

*) The alpha.jar's dependent jars are also in war/WEB-INF/lib. log4j2-core, log4j-api as well as a bunch of others (apache common for example)

*) If I remove the alpha.jar (and the code that calls it) and instead just add code that called LOG4J2, that code also works fine!

How come I get this weird error when using the JAR?? Note also the NoClassDefFoundError, its not the more common ClassNotFoundException. Pls see What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?

If you need more info let me know.

解决方案

org.apache.log4j.LogManager is a class from log4j 1.2 (not log4j2).

Therefore, one of your web app jars must be referencing it. The culprit should be visible in the stack trace.

Depending upon your circumstances, you may want to just add a log4j 1.2 jar to the web app as the two versions are completely independent of each other.

这篇关于意外异常:java.lang.NoClassDefFoundError:org / apache / log4j / LogManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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