我想在中使用embedded tomcat
而不是独立版本来启动web应用程序。为了做到这一点,我在pom.xml
中声明了tomcat maven插件。当我尝试启动它时,我得到了这个错误:
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at org.apache.tomcat.maven.plugin.tomcat7.run.RunMojo$2.run(RunMojo.java:295)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 1 more
这是我的POM.xml的配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat-maven-plugin.version}</version>
<configuration>
<port>8080</port>
<path>/ppc-v2.webapp</path>
</configuration>
<dependencies>
<dependency>
<groupId>upgrade.karavel.framework</groupId>
<artifactId>framework.integration.camel.extension</artifactId>
<version>${framework.camel.extension.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>upgrade.karavel.framework</groupId>
<artifactId>framework.frontend.web</artifactId>
<version>${framework.frontend.web.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
编辑:我在日志的顶部有以下堆栈:
GRAVE:一个子容器在启动过程中失败java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine[TTomcat].StandardHost[localhost].StandardsContext[/ppc-v2.webapp]]位于java.util.concurrent.FFutureTask.report(FutureTask.java:122)位于java.util.concurrent.FFutureTask.get(FutureTask.java:192)网址:org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)网址:org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)网址:org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)网址:org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)位于java.util.concurrent.FFutureTask.run(FutureTask.java:266)位于java.util.concurrent.ThreadPoolExecutiator.runWorker(ThreadPoolExecutiator.java:1149)位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)在java.lang.Thread.run(线程.java:748)由以下原因引起:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine[Tomcat].StandardHost[localhost].StandardsContext[/ppc-v2.webapp]]网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)…还有6个由以下原因引起:java.lang.ClassCastException:org.springframework.web.SpringServlet ContainerInitializer无法强制转换为javax.servlet。servlet ContainerInitialize位于org.apache.catalina.startup.ContextConfig.getServlet容器初始化器(ContextConfig.java:1670)位于org.apache.catalina.startup.ContextConfig.getServlet容器初始化器(ContextConfig.java:1652)网址:org.apache.catalina.startup.ContextConfig.processServlet容器初始化程序(ContextConfig.java:1562)网址:org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)网址:org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)网址:org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)网址:org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)网址:org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)网址:org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)…还有6个2018年9月3日下午12:34:07 org.apache.catalina.core.ContainerBase启动内部GRAVE:一个子容器在启动过程中发生故障java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine[TTomcat].StandardHost[localhost]]位于java.util.concurrent.FFutureTask.report(FutureTask.java:122)位于java.util.concurrent.FFutureTask.get(FutureTask.java:192)网址:org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)网址:org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)网址:org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)网址:org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)网址:org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)网址:org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1238)网址:org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:592)网址:org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)网址:org.apache.maven.hifecycle.internal.MojoExecution.execute(MojoExecutitor.java:208)网址:org.apache.maven.hifecycle.internal.MojoExecution.execute(MojoExecutitor.java:153)网址:org.apache.maven.hifecycle.internal.MojoExecution.execute(MojoExecutitor.java:145)网址:org.apache.maven.hifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModelBuilder.java:116)网址:org.apache.maven.hifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModelBuilder.java:80)网址:org.apache.maven.hifecycle.internal.builders.singlethreaded.SingleThreaddBuilder.build(SingleThreaddBBuilder.java:51)网址:org.apache.maven.hifecycle.internal.LifecycleStarter.execute(LifecycleSstarter.java:120)网址:org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)网址:org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)网址:org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)网址:org.apache.maven.cli.MavenCli.main(MavenCli.java:158)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于java.lang.reflect.Method.ioke(Method.java:498)网址:org.codehaus.cluster.classworlds.launcher.launcher.launchEnhanced(launcher.java:289)网址:org.codehaus.cluster.classworlds.launcher.launcher.launch(launcher.java:229)网址:org.codehaus.cluster.classworlds.launcher.launcher.mainWithExitCode(launcher.java:415)网址:org.codehaus.cluster.classworlds.launcher.launcher.main(launcher.java:356)导致原因:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine[Tomcat].StandardHost[localhost]]网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)网址:org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)网址:org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)位于java.util.concurrent.FFutureTask.run(FutureTask.java:266)位于java.util.concurrent.ThreadPoolExecutiator.runWorker(ThreadPoolExecutiator.java:1149)位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)在java.lang.Thread.run(线程.java:748)由:org.apache.catalina.LifecycleException引起:启动期间子容器失败网址:org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)网址:org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)网址:org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)…还有6个
您可以通过在pom.xml 中添加此依赖项来包含Apache commons io jar
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
如果你想在tomcatlib中添加jar文件,你所能做的就是从https://commons.apache.org/proper/commons-io/download_io.cgi然后转到安装tomcat的位置,转到lib文件夹并复制粘贴jar。就我而言,我的位置是
C:Program FilesApache Software FoundationTomcat 9.0lib
您也可以在本地系统中进行类似的检查。
谢谢大家,但您无法解决我的问题:D我注意到我仍然使用jetty插件,其中一个名为jetty-jndi的依赖项(包括servlet api)与嵌入式tomcat的servlet api发生了冲突。由于某种未知的原因,我在maven依赖项:Eclipse的树中看不到这个jar。
这就是我犯这个错误的原因。
谢谢大家。
致以最诚挚的问候