Apusic中log4j无法装载问题的解决

部署在Apusic 4.0.3上的应用中,使用到log4j,在应用装载时报如下异常:

2008-05-27 20:00:41 错误 [apusic.server.Main] 启动 'apusic:name=J2EEDeployer,j2eeType=Service' 服务失败。
java.lang.ExceptionInInitializerError
at org.apache.struts.action.ActionServlet.initInternal(ActionServlet.java:1013)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:322)
at com.tjsoft.system.CTJActionServlet.init(CTJActionServlet.java:27)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at com.apusic.servlet.http.ServletConfigImpl.initializeComponent(Unknown Source)
at com.apusic.servlet.http.ServletConfigImpl.initializeComponent(Unknown Source)
at com.apusic.servlet.http.ComponentConfigImpl.createComponent(Unknown Source)
at com.apusic.servlet.http.ComponentConfigImpl.getComponent(Unknown Source)
at com.apusic.servlet.http.ServletConfigImpl.getServlet(Unknown Source)
at com.apusic.servlet.http.Context.loadStartupServlets(Unknown Source)
at com.apusic.servlet.http.Context.start(Unknown Source)
at com.apusic.servlet.http.VirtualHost.addContext(Unknown Source)
at com.apusic.servlet.http.HttpServer.loadWebModule(Unknown Source)
at com.apusic.servlet.http.WebService.loadWebModule(Unknown Source)
at com.apusic.deploy.runtime.J2EEApplication.loadWebModule(Unknown Source)
at com.apusic.deploy.runtime.J2EEApplication.startApplication(Unknown Source)
at com.apusic.deploy.runtime.J2EEApplication.startService(Unknown Source)
at com.apusic.service.Service.start(Unknown Source)
at com.apusic.deploy.runtime.J2EEDeployer.startUserApplications(Unknown Source)
at com.apusic.deploy.runtime.J2EEDeployer.startService(Unknown Source)
at com.apusic.service.Service.start(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.apusic.jmx.MBeanDescriptor.invoke(Unknown Source)
at com.apusic.jmx.DynamicMBeanSupport.invoke(Unknown Source)
at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:221)
at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:228)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:822)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:792)
at com.apusic.server.J2EEServer.start(Unknown Source)
at com.apusic.server.J2EEServer.startup(Unknown Source)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@20ca8b for org.apache.commons.logging.impl.Log4JCategoryLog
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:532)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:272)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:246)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:395)
at org.apache.struts.util.MessageResources.(MessageResources.java:59)
... 32 more
Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@20ca8b for org.apache.commons.logging.impl.Log4JCategoryLog
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:432)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:525)
... 36 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:429)
... 37 more


引起此异常的原因是Apusic的system classloader中,已经加载了commons-logging类,而log4j的类是在下一级的servlet classloader中加载的,对system classloader加载的类来说不可见,因此报“java.lang.NoClassDefFoundError”。

解决的办法由多种,下面介绍常用的2种:

1. 将log4j的jar包加入到APUSIC_HOME/lib目录,并且在APUSIC_HOME/bin/startapusic.cmd(linux下是startapusic)中的java命令行中,通过添加 -Dlog4j.configuration=your_log4j_configuration_file指定log4j的配置文件。

2. 在APUSIC_HOME/bin/startapusic.cmd(linux下是startapusic)中的java命令行中,通过添加 -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值