【问题标题】:'org.apache.commons.logging.impl.Log4JLogger' cannot be found [closed]找不到“org.apache.commons.logging.impl.Log4JLogger”[关闭]
【发布时间】:2013-03-25 01:15:15
【问题描述】:

在我的 Java Web 服务中,我正在尝试使用 log4j 将日志写入 Windows 事件查看器。我使用 Eclipse 作为 IDE 来使用 Tomcat 部署它。

这是我的 log4j.properties:

log4j.rootLogger=DEBUG, CA, NTEventLog 


log4j.rootLogger=DEBUG, CA, NTEventLog 


#Console Appender 
log4j.appender.CA=org.apache.log4j.ConsoleAppender 
log4j.appender.CA.layout=org.apache.log4j.PatternLayout 
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 

#File Appender 
log4j.appender.FA=org.apache.log4j.FileAppender 
log4j.appender.FA.File=sample.log 
log4j.appender.FA.layout=org.apache.log4j.PatternLayout 
log4j.appender.FA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

#Event Log Appender
log4j.appender.NTEventLog=org.apache.log4j.nt.NTEventLogAppender
log4j.appender.NTEventLog.source=ESB Web Services


# Set the logger level of File Appender to WARN 
log4j.appender.FA.Threshold = WARN

这是我的类路径:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre6">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="lib" path="dom4j-1.6.1.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="jide-oss-2.1.1.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="jtds-1.2.6.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="poi-3.9-20121203.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="poi-ooxml-3.9-20121203.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="poi-ooxml-schemas-3.9-20121203.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="stax-api-1.0.1.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="xmlbeans-2.3.0.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="NTEventLogAppender.amd64.dll">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="NTEventLogAppender.dll">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="log4j-1.2.17.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-1.1.2.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-1.1.2-javadoc.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-1.1.2-sources.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-1.1.2-test-sources.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-1.1.2-tests.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-adapters-1.1.2.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-api-1.1.2.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="commons-logging-tests.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="build/classes"/>
</classpath>

一旦我在 tomcat 上部署代码,如下

出现异常:

org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
    at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:874)
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at org.apache.axis2.deployment.DeploymentEngine.<clinit>(DeploymentEngine.java:76)
    at org.apache.axis2.transport.http.AxisServlet.initConfigContext(AxisServlet.java:584)
    at org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:454)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

【问题讨论】:

  • 你有 log4j jar 放在 tomcat 的 WEB-INF/lib 文件夹下吗?
  • remove NTEventLog 也没有正确配置。
  • 这里:workspace\Project\WebContent\WEB-INF\lib @linski
  • 你是什么意思@RomanC​​pan>
  • @user1912404 没有布局,来源可疑。

标签: java eclipse tomcat log4j


【解决方案1】:

删除所有NTEventLog 的引用,它将起作用。如果您取消注释此附加程序,如果源是有效名称,它可能会起作用。

#log4j.rootLogger=DEBUG,CA,NTEventLog 
log4j.rootLogger=DEBUG,CA        

#Console Appender 
log4j.appender.CA=org.apache.log4j.ConsoleAppender 
log4j.appender.CA.layout=org.apache.log4j.PatternLayout 
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 

#File Appender 
log4j.appender.FA=org.apache.log4j.FileAppender 
log4j.appender.FA.File=sample.log 
log4j.appender.FA.layout=org.apache.log4j.PatternLayout 
log4j.appender.FA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

#Event Log Appender
#log4j.appender.NTEventLog=org.apache.log4j.nt.NTEventLogAppender
#log4j.appender.NTEventLog.layout=org.apache.log4j.PatternLayout
#log4j.appender.NTEventLog.layout.ConversionPattern=%m%n
#log4j.appender.NTEventLog.source=ESBWebServices


# Set the logger level of File Appender to WARN 
log4j.appender.FA.Threshold = WARN

不要忘记将 NTEventLogAppender.dll、NTEventLogAppender.amd64.dll、NTEventLogAppender.ia64.dll 或 NTEventLogAppender.x86.dll 适当地放置在 Windows 系统 PATH 上的目录中。否则,您将收到 java.lang.UnsatisfiedLinkError。

【讨论】:

  • 但我遇到了另一个错误:java.lang.UnsatisfiedLinkError: no NTEventLogAppender in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown来源)在 java.lang.System.loadLibrary(未知来源)
  • 代码在这一行崩溃:NTEventLogAppender eventLogAppender = new NTEventLogAppender();
  • 我只是将 dll 添加到类路径中,如上所示
  • 请再看一遍答案,我已经编辑过了
  • 你需要把dll放到路径中。
【解决方案2】:

这可能是个问题:类文件存在于您的类路径中的两个 jar 中。

类文件:org.apache.commons.logging.impl.Log4JLogger

第一个罐子:commons-logging-1.1.2.jar

第二罐:commons-logging-adapters-1.1.2.jar

尝试移除第二个 jar 并重试。

【讨论】:

  • 同样的错误,它不起作用
【解决方案3】:

我认为在 TOMCAT_HOME/lib 中有一个 commons-logging 副本,因此您可能会遇到类路径冲突,但我会检查 apache commons logging 文档以确保您已正确设置它。

【讨论】:

  • 我检查了这个路径 C:\Users\KELEL\Desktop\apache-tomcat-6.0.36\lib 并且我没有找到 commons-logging 的副本
  • 在tomcat\lib中添加jar
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 2021-02-14
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多