2012-02-18 99 views
6

幾個問題:在Eclipse中運行我的maven項目 - 在服務器上運行不會到來。 2),所以我想直接在Tomcat服務器在運行,WO當我嘗試創建戰爭以下錯誤快到了。請幫助我,我有我的web.xml文件中指定的路徑只有無法在maven項目中構建戰爭

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) 
on project SchoolMgmtApp: The specified web.xml file 
'F:\WorkSpace\SchoolMgmtApp\src\main\webapp\WEB-INF\web.xml' does not exist - 

回答

22

我認爲這個錯誤是自我解釋的。您的項目中沒有web.xml。這是打算?從理論上說,你可以擁有一個沒有web.xml文件的WAR文件,因爲Servlet 3.0支持這種部署。在這種情況下,您必須像這樣配置maven-war插件:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.2</version> 
    <configuration> 
    <failOnMissingWebXml>false</failOnMissingWebXml> 
    </configuration> 
</plugin> 
+0

的web.xml是thier店指定的路徑 – 2012-02-19 03:47:29

+1

所以文件是有,但Maven的抱怨難道不是嗎?也許文件權限問題? – chkal 2012-02-19 07:59:57

+0

是的,當然,由於文檔顯式狀態爲failOnMissingWebXml是必需的。對於提及Servlet 3.0異常的chkal有額外的讚賞,這是現貨! – TechTrip 2013-08-28 21:51:12

5

您的web.xml可能不在標準位置。一些Eclipse項目創建嚮導將web.xml放入WebContent/WEB_INF中。在這種情況下,您可以重新安排項目,讓maven喜歡它,或者你可以告訴maven在pom.xml中的哪裏可以找到你的web.xml文件。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <configuration> 
    <webXml>WebContent\WEB-INF\web.xml</webXml> 
    ... 
0

我覺得你在尋找這樣的事情:

<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <warName>${applicationContextName}</warName> 
     <packagingExcludes> 
      AFolder, 
      aFile.xml 
     </packagingExcludes> 
    </configuration> 
    <executions> 
     <execution> 
      <id>default-war</id> 
      <phase>package</phase> 
      <goals> 
       <goal>war</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin>