当前位置: 首页 > 知识库问答 >
问题:

noClassDefFoundError:lorg/slf4j/logger

汪明德
2023-03-14

我将使用支持maven的Intellij启动tomcat。一旦我添加了以下tomcat maven依赖项:

        <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-catalina</artifactId>
        <version>8.5.38</version>
    </dependency>

启动时,它将抛出此异常:

Caused by: java.lang.NoClassDefFoundError: Lorg/slf4j/Logger;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:110)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:269)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:89)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:772)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 44 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1364)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1185)
... 57 more

25-Feb-2019 00:51:29.242 SEVERE [RMI TCP Connection(4)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method manageApp
  java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/web_war_exploded]]

我已经检查了slf4j的依赖关系:

        <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.22</version>
    </dependency>

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0

<groupId>chrisTina</groupId>
<artifactId>Insbot</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.8.1</version>
    </dependency>

    <!--<dependency>-->
        <!--<groupId>org.apache.logging.log4j</groupId>-->
        <!--<artifactId>log4j-slf4j-impl</artifactId>-->
        <!--<version>2.11.1</version>-->
    <!--</dependency>-->

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.4</version>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.typesafe/config -->
    <dependency>
        <groupId>com.typesafe</groupId>
        <artifactId>config</artifactId>
        <version>1.2.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.awaitility/awaitility -->
    <dependency>
        <groupId>org.awaitility</groupId>
        <artifactId>awaitility</artifactId>
        <version>3.1.6</version>
        <!--<scope>test</scope>-->
    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.15</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.4.1.Final</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
    <dependency>
        <groupId>net.bytebuddy</groupId>
        <artifactId>byte-buddy</artifactId>
        <version>1.9.10</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.0</version>
    </dependency>

    <!--&lt;!&ndash; https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api &ndash;&gt;-->
    <!--<dependency>-->
        <!--<groupId>javax.servlet</groupId>-->
        <!--<artifactId>javax.servlet-api</artifactId>-->
        <!--<version>4.0.1</version>-->
        <!--<scope>provided</scope>-->
    <!--</dependency>-->


    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.22</version>
    </dependency>

    <!--&lt;!&ndash; https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 &ndash;&gt;-->
    <!--<dependency>-->
        <!--<groupId>org.slf4j</groupId>-->
        <!--<artifactId>slf4j-log4j12</artifactId>-->
        <!--<version>1.7.22</version>-->
    <!--</dependency>-->

    <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
    <!--<dependency>-->
        <!--<groupId>org.apache.tomcat</groupId>-->
        <!--<artifactId>tomcat-catalina</artifactId>-->
        <!--<version>8.5.38</version>-->
    <!--</dependency>-->

</dependencies>

<packaging>war</packaging>

MVN输出:

    [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ Insbot ---
[INFO] chrisTina:Insbot:war:1.0-SNAPSHOT
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-api:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-edge-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-opera-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-safari-driver:jar:3.8.1:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:3.8.1:compile
[INFO] |  +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.8.2:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.3:compile
[INFO] |  \- org.apache.httpcomponents:httpcore:jar:4.4.6:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.4:provided
[INFO] +- com.typesafe:config:jar:1.2.0:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.8.1:compile
[INFO] +- org.awaitility:awaitility:jar:3.1.6:compile
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:compile
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] |  \- org.objenesis:objenesis:jar:2.6:compile
[INFO] +- mysql:mysql-connector-java:jar:8.0.15:compile
[INFO] |  \- com.google.protobuf:protobuf-java:jar:3.6.1:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.4.1.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] |  +- org.javassist:javassist:jar:3.24.0-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final:compile
[INFO] |  +- org.jboss:jandex:jar:2.0.5.Final:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  \- org.glassfish.jaxb:jaxb-runtime:jar:2.3.1:compile
[INFO] |     +- org.glassfish.jaxb:txw2:jar:2.3.1:compile
[INFO] |     +- com.sun.istack:istack-commons-runtime:jar:3.0.7:compile
[INFO] |     +- org.jvnet.staxex:stax-ex:jar:1.8:compile
[INFO] |     \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.15:compile
[INFO] +- net.bytebuddy:byte-buddy:jar:1.9.10:compile
[INFO] +- com.google.guava:guava:jar:23.0:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] \- org.apache.tomcat:tomcat-catalina:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-servlet-api:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-jsp-api:jar:8.5.38:compile
[INFO]    |  \- org.apache.tomcat:tomcat-el-api:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-juli:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-annotations-api:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-api:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-jni:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-coyote:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-util:jar:8.5.38:compile
[INFO]    +- org.apache.tomcat:tomcat-util-scan:jar:8.5.38:compile
[INFO]    \- org.apache.tomcat:tomcat-jaspic-api:jar:8.5.38:compile

共有1个答案

龚运乾
2023-03-14

您需要将。jar文件添加到lib文件夹$tomcat/webapps/$your_web_app/web-inf/lib/

 类似资料:
  • 我在我的项目中使用log4j2和slf4j 信息: pom文件 更新:我在pom文件中添加了以下依赖项,我在mavenrepository中看到了jar——尽管在运行mvn clean/install时仍然看到相同的消息

  • SLF4J是为各种loging APIs提供一个简单统一的接口,从而使得最终用户能够在部署的时候配置自己希望的loging APIs实现。 Logging API实现既可以选择直接实现SLF4J接的loging APIs如: NLOG4J、SimpleLogger。也可以通过SLF4J提供的API实现来开发相应的适配器如Log4jLoggerAdapter、JDK14LoggerAdapter。

  • SLF4J Taglib 是一个使用 SLF4J 进行日志输出的JSP标签库,用法如下: <%@ taglib prefix="log" uri="http://www.slf4j.org/taglib/tld" %> <log:debug category="foo.bar">this is a debug message</log:debug>

  • SLF4J Android 是一个在 Android 平台上使用的日志框架,跟 SLF4J 普通用法一样: private static final Logger logger = LoggerFactory.getLogger(MyClass.class); logger.debug("Some log message. Details: {}", someObject.toString());

  • 主要内容:SLF4J的优点SLF4J代表Simple Logging Facade for Java。它提供了Java中所有日志框架的简单抽象。因此,它使用户能够使用单个依赖项处理任何日志框架,例如:Log4j,Logback和JUL()。可以在运行时/部署时迁移到所需的日志记录框架。 CekiGülcü创建了SLF4J作为框架的替代品。 SLF4J的优点 以下是SLF4J的优点 - 使用SLF4J框架,可以在部署时迁移到

  • 主要内容:面向读者,前提条件,问题反馈SLF4J代表Simple Logging Facade for Java。 它提供了对所有日志框架的简单抽象。 它使用户能够使用单一依赖关系使用任何日志框架,如:Log4j,Logback,JUL(java.util.logging)等。 面向读者 本教程是为SLF4J初学者准备的,以帮助他们理解SLF4J日志框架的基本功能。 前提条件 当在各种基于Java的应用程序开发中使用SLG4J日志记录