在将Tomcat Embedded与Maven结合使用时启动应用程序

时间:2018-09-03 09:26:24

标签: java maven tomcat7 apache-commons-io tomcat7-maven-plugin

我想使用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 [Tomcat] .StandardHost [localhost] .StandardContext [/ppc-v2.webapp]]       在java.util.concurrent.FutureTask.report(FutureTask.java:122)       在java.util.concurrent.FutureTask.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.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)       在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)       在java.lang.Thread.run(Thread.java:748)   由以下原因引起:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost] .StandardContext [/ppc-v2.webapp]]       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)       ...另外6个   引起原因:java.lang.ClassCastException:org.springframework.web.SpringServletContainerInitializer无法转换为javax.servlet.ServletContainerInitializer       在org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1670)       在org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652)       在org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(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个   九月03,2018 12:34:07 PM org.apache.catalina.core.ContainerBase startInternal   GRAVE:子容器在启动过程中失败   java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost]]       在java.util.concurrent.FutureTask.report(FutureTask.java:122)       在java.util.concurrent.FutureTask.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.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.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.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)       在org.codehaus.plexus.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.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)       在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)       在java.lang.Thread.run(Thread.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个

2 个答案:

答案 0 :(得分:0)

您可以通过在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>

如果您要将jar文件添加到tomcat lib中,您所能做的就是从https://commons.apache.org/proper/commons-io/download_io.cgi下载jar文件 并转到已安装tomcat的位置,然后转到lib文件夹并复制粘贴jar。就我而言,我的位置是

C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib

您可以类似地在本地系统中签入。

答案 1 :(得分:0)

谢谢大家,但您无法解决我的问题:D 我注意到我仍在使用jetty插件,并且其中一个名为jetty-jndi的依赖项(其中包括servlet-api)与嵌入式tomcat的servlet-api有冲突。由于某些未知的原因,我在maven依赖项:Eclipse树中看不到这个jar。

这就是我收到此错误的原因。

谢谢。

最好的问候