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

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

问题描述

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

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.

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

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.

问题:

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

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.

在 GWT 中通过向 Alpha 项目添加构建路径引用来执行此操作时,我的 GWT 应用程序运行良好.

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

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

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.

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

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?

注意以下几点:

*) alpha.jar 的依赖 jars 也在 war/WEB-INF/lib 中.log4j2-core、log4j-api 以及其他一些(例如常见的 apache)

*) 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)

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

*) 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!

我在使用 JAR 时怎么会出现这个奇怪的错误??还要注意 NoClassDefFoundError,它不是更常见的 ClassNotFoundException.请参阅 NoClassDefFoundError 和 ClassNotFoundException 的原因和区别是什么?

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 是 log4j 1.2(不是 log4j2)中的一个类.

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

因此,您的 Web 应用 jar 包之一必须引用它.罪魁祸首应该在堆栈跟踪中可见.

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

根据您的情况,您可能只想向 Web 应用程序添加一个 log4j 1.2 jar,因为这两个版本彼此完全独立.

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天全站免登陆