没有 web.xml 如何使用 Maven 打 war 包?

黄勇 发布于 2013/09/04 13:04
阅读 5K+
收藏 1

我使用 Servlet 3 开发了一个 Web 应用,打算采用 Maven 打 war 包。执行 mvn package 命令后,出现如下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project smart-sample: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

请问应该如何解决?

加载中
1
黄勇
黄勇

原来 Maven 提供的 war 插件已经考虑到了,将 failOnMissingWebXml 设置为 false 即可。

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

返回顶部
顶部