即使在创建对象之后也会抛出 NoClassDefFoundError
创建实例后,我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说这看起来像是一个类加载器问题。您正在一个具有分层类加载器的系统中工作,例如 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.