简体   繁体   English

带有maven的Eclipse Dynamic Web Project在mvn tomcat7:run上抛出错误

[英]Eclipse Dynamic Web Project with maven is throwing error on mvn tomcat7:run

I created a dynamic web project in eclipse Luna and then converted the same to maven project. 我在eclipse Luna中创建了一个动态Web项目,然后将其转换为maven项目。 I specified dependencies as follows: 我指定了依赖项如下:

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

and also updated tomcat7 plugin as 并且还更新了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>

but after mvn clean install followed by mvn tomcat7:run I got the following error: 但是在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

I know there is no directory as src/main/webapp as it is not classical maven webapp. 我知道没有目录作为src/main/webapp因为它不是经典的maven webapp。 How can I avoid this error and start my tomcat7 normally as usual? 如何避免此错误并像往常一样正常启动我的tomcat7?

In case you are not using the standard webapp folder, instruct the plugin to use the directory where your web resources are located.Something like the below should fix it. 如果您没有使用标准的webapp文件夹,请指示插件使用您的Web资源所在的目录。以下内容应该修复它。

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

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

META-INFWEB-INFsrc/main/webapp解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM