即使在创建对象之后也会抛出 NoClassDefFoundError

发布于 2025-01-08 17:36:39 字数 2293 浏览 1 评论 0原文

创建实例后,我在 org.apache.commons.logging.LogFactory 上收到 NoClassDefFoundError 异常。我可以很好地创建一个 LogFactory 对象并从中获取 org.apache.commons.logging.Log 的实例,但是在创建 org.apache.commons.logging.Log 类型的对象时。 apache.axis.description.TypeDesc,当此类尝试从 org.apache.commons.logging.Log 获取实例时,会引发 NoClassDefFoundError LogFactory。似乎应该在第 284 行抛出异常。(?)

这是我的代码(DtUiLoggingRequest 第 282 至 294 行);

log.debug("vvvvvvvvvvvvvvvv");

org.apache.commons.logging.LogFactory logFactory = (org.apache.commons.logging.LogFactory)LogFactory.getFactory();
Log myLog = LogFactory.getLog(DtUiLoggingRequest.class.getName());

log.debug(logFactory.getClass().getName());
log.debug(myLog.getClass().getName());

myLog.debug("This is coming from 'myLog'");

log.debug("^^^^^^^^^^^^^^^^");

typeDesc = new org.apache.axis.description.TypeDesc(DtUiLoggingRequest.class);

日志是这样写的;

DEBUG   2012-02-23 09:32:08,739 vvvvvvvvvvvvvvvv  
DEBUG   2012-02-23 09:32:08,739 org.apache.commons.logging.impl.LogFactoryImpl  
DEBUG   2012-02-23 09:32:08,739 org.apache.commons.logging.impl.Log4JLogger  
DEBUG   2012-02-23 09:32:08,739 ^^^^^^^^^^^^^^^^  
ERROR   2012-02-23 09:32:08,739 Exception Details:  
java.lang.NoClassDefFoundError: org.apache.commons.logging.LogFactory  
    at org.apache.axis.components.logger.LogFactory.class$(LogFactory.java:45)  
    at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:45)  
    at java.security.AccessController.doPrivileged(Native Method)  
    at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)  
    at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)  
    at org.apache.axis.description.TypeDesc.<clinit>(TypeDesc.java:61)  
    at com.symantec.cas.ucf.sensors.DtUiLoggingRrequest.initTypeDesc(DtUiLoggingRequest.java:294)  
    at com.symantec.cas.ucf.sensors.sap.DtUiLoggingRequest.<init>(DtUiLoggingRequest.java:58)  
    at com.symantec.cas.ucf.sensors.sap.SapSensor.OpenDevice(Sensor.java:151)  
    at com.symantec.cas.ucf.collector.SensorJob.openSensor(SensorJob.java:156)  
    at com.symantec.cas.ucf.collector.SensorJob.run(SensorJob.java:290)  
    at java.lang.Thread.run(Thread.java:662)  

I'm getting a NoClassDefFoundError exception on org.apache.commons.logging.LogFactory after I have already created an instance. I can create a LogFactory object just fine and get an instance of org.apache.commons.logging.Log from it but when creating an object of type org.apache.axis.description.TypeDesc, a NoClassDefFoundError is thrown when this class tries to get an instance of org.apache.commons.logging.Log from LogFactory. Seems like an exception should be thrown at line 284.(?)

Here's my code (DtUiLoggingRequest lines 282 to 294);

log.debug("vvvvvvvvvvvvvvvv");

org.apache.commons.logging.LogFactory logFactory = (org.apache.commons.logging.LogFactory)LogFactory.getFactory();
Log myLog = LogFactory.getLog(DtUiLoggingRequest.class.getName());

log.debug(logFactory.getClass().getName());
log.debug(myLog.getClass().getName());

myLog.debug("This is coming from 'myLog'");

log.debug("^^^^^^^^^^^^^^^^");

typeDesc = new org.apache.axis.description.TypeDesc(DtUiLoggingRequest.class);

Here's what the log says;

DEBUG   2012-02-23 09:32:08,739 vvvvvvvvvvvvvvvv  
DEBUG   2012-02-23 09:32:08,739 org.apache.commons.logging.impl.LogFactoryImpl  
DEBUG   2012-02-23 09:32:08,739 org.apache.commons.logging.impl.Log4JLogger  
DEBUG   2012-02-23 09:32:08,739 ^^^^^^^^^^^^^^^^  
ERROR   2012-02-23 09:32:08,739 Exception Details:  
java.lang.NoClassDefFoundError: org.apache.commons.logging.LogFactory  
    at org.apache.axis.components.logger.LogFactory.class$(LogFactory.java:45)  
    at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:45)  
    at java.security.AccessController.doPrivileged(Native Method)  
    at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)  
    at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)  
    at org.apache.axis.description.TypeDesc.<clinit>(TypeDesc.java:61)  
    at com.symantec.cas.ucf.sensors.DtUiLoggingRrequest.initTypeDesc(DtUiLoggingRequest.java:294)  
    at com.symantec.cas.ucf.sensors.sap.DtUiLoggingRequest.<init>(DtUiLoggingRequest.java:58)  
    at com.symantec.cas.ucf.sensors.sap.SapSensor.OpenDevice(Sensor.java:151)  
    at com.symantec.cas.ucf.collector.SensorJob.openSensor(SensorJob.java:156)  
    at com.symantec.cas.ucf.collector.SensorJob.run(SensorJob.java:290)  
    at java.lang.Thread.run(Thread.java:662)  

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

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

发布评论

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

评论(1

望笑 2025-01-15 17:36:39

对我来说这看起来像是一个类加载器问题。您正在一个具有分层类加载器的系统中工作,例如 Web 应用程序,并且 Axis 正在由比 Commons Logging 状态更高的类加载器加载。这意味着,即使 Commons Logging 位于您的系统中,Axis 也不允许看到它。我的大胆猜测是,您正在从 JRE 扩展目录加载 Axis,但从您的 war 文件加载 Commons Logging。

This looks like a classloader issue to me. You're working in a system with hierarchical classloaders, like a web app, and Axis is being loaded by a higher-status classloader than Commons Logging. That means that, even though Commons Logging is in your system, Axis is not allowed to see it. My wild-arsed guess would be that you're loading Axis from a JRE extension directory, but Commons Logging from your war file.

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