【问题标题】:Eclipse Dynamic Web Project with maven is throwing error on mvn tomcat7:run带有 maven 的 Eclipse 动态 Web 项目在 mvn tomcat7:run 上抛出错误
【发布时间】:2014-10-18 11:04:33
【问题描述】:

我在 Eclipse Luna 中创建了一个动态 Web 项目,然后将其转换为 maven 项目。 我指定的依赖项如下:

<dependencies>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1102-jdbc41</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

并且还更新了tomcat7插件为

<plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.0</version>
        <configuration>
          <port>8080</port>
          <path>/</path>
        </configuration>
      </plugin>

但在mvn clean install 后跟mvn tomcat7:run 之后出现以下错误:

SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /home/dheerendra/workspace/myproject/src/main/webapp does not exist or is not a readable directory
    at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:140)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4906)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5086)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Oct 18, 2014 4:24:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Oct 18, 2014 4:24:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Oct 18, 2014 4:24:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors

我知道没有像 src/main/webapp 这样的目录,因为它不是经典的 maven webapp。我怎样才能避免这个错误并像往常一样正常启动我的tomcat7?

【问题讨论】:

    标签: java eclipse maven tomcat7 web-project


    【解决方案1】:

    如果您没有使用标准的 webapp 文件夹,请指示插件使用您的网络资源所在的目录。类似下面的内容应该可以修复它。

      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.0</version>
        <configuration>
          <port>8080</port>
          <path>/</path>
          <warSourceDirectory>src/mywebappfolder</warSourceDirectory>
        </configuration>
      </plugin>
    

    参考:http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html

    【讨论】:

    • 谢谢,它成功了。但是 maven 仍然没有检测到 web.xml 中指定的 WebContent 文件夹中的文件作为欢迎文件。有什么解决办法吗?
    【解决方案2】:

    META-INFWEB-INF 移动到src/main/webapp 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 2015-06-27
      • 1970-01-01
      相关资源
      最近更新 更多