gpt4 book ai didi

java.lang.NoClassDefFoundError : Lorg/slf4j/Logger

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:12 32 4
gpt4 key购买 nike

我正在使用具有 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>

它显示它有类org.slf4j.Logger:

如果我删除 tomcat 依赖项,一切都会再次正常工作。

enter image description here

更新:

我的pom文件:

<?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

最佳答案

您需要将 .jar 文件添加到 lib 文件夹$TOMCAT/webapps/$YOUR_WEB_APP/WEB-INF/lib/

关于java.lang.NoClassDefFoundError : Lorg/slf4j/Logger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54860329/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com