我正在使用具有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依赖项,一切都会恢复正常。
更新:
我的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>
<!--<!– https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api –>-->
<!--<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>
<!--<!– https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 –>-->
<!--<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
答案 0 :(得分:0)
您需要将.jar文件添加到lib文件夹$TOMCAT/webapps/$YOUR_WEB_APP/WEB-INF/lib/
答案 1 :(得分:0)
在此添加答案的原因仅在于,当我尝试调查一个稍有不同的问题时,这个问题是第一个相关的搜索结果:使用Eclipse和Tomcat运行应用程序-会出现相同的错误。我从来没有意识到Eclipse(有时?是我的特殊之处吗?)不会从Maven生成的WAR文件中复制lib目录-因此,即使必需的jar文件位于WAR内,Eclipse也不使用它们-在服务器(特别是Tomcat)上的运行或调试时,在Tomcat服务器的wtpwebapps目录中,它使用某种分解结构。因此,正如其他人在其他需要解决的问题中指出的那样,有必要通过项目属性将Java构建路径条目-Maven依赖项添加到Deployment Assembly中-其他工具可能会发生类似的事情
P.S。是的,正如其他人指出的那样,在Eclipse中执行Maven-> Update Project通常会搞乱上述配置
P.P.S。抱歉,Eclipse –上面的原因是我的pom.xml配置不当-每个Maven期间Eclipse所做的工作->“更新项目”是将pom.xml中的任何配置复制到其自己的项目配置中-因此,当依赖项不是明确表示要在pom.xml中复制,但不会复制(重置项目属性)-根据here
的回答,我已解决此问题答案 2 :(得分:0)
如果使用的是Eclipse,则文件 .classpath 需要指出lib路径。因此,请检查此行是否包含在我们的设置中。
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
”
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>