无法在maven项目中建立战争

时间:2012-02-18 06:01:26

标签: web-applications maven

一些问题:在Eclipse中我的maven项目运行时 - 在服务器上运行不会到来。                   2)所以我想直接在tomcat服务器上运行,当我尝试创建war时,会出现以下错误。请帮助我,我只在指定的路径中使用我的web.xml

   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 -

3 个答案:

答案 0 :(得分:22)

我认为错误是自我解释的。您的项目中没有web.xml。这是有意的吗?理论上,您可以拥有一个没有web.xml文件的WAR文件,因为Servlet 3.0支持这种部署。在这种情况下,你必须像这样配置maven-war-plugin:

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

答案 1 :(得分: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>
    ...

答案 2 :(得分: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>
相关问题