2014-10-18 116 views
1

我在eclipse Luna中創建了一個動態web項目,然後將其轉換爲maven項目。 我指定的依賴如下:帶有maven的Eclipse動態Web項目在mvn tomcat7上拋出錯誤:運行

<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 tomcat7:runmvn clean install我得到了以下錯誤:

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?

回答

4

如果你沒有使用標準的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> 

參見:http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html

+0

謝謝,它工作。但是maven仍然沒有將web.xml中指定的WebContent文件夾中的文件檢測爲歡迎文件。任何解決方案? – Dheerendra 2014-10-18 11:37:46

0

移動META-INFWEB-INFsrc/main/webapp解決了這個問題。

相關問題