mvn install一個web項目時,報錯如下:error assembling war:webxml attribute is required
[error] failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war
(default-war) on project com.alpha.webapp: 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] 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
原因:
maven的web項目預設的webroot是在src\main\webapp。如果在此目錄下找不到web.xml就抛出以上的異常。
解決辦法:需要在pom.xml中增加<webresources>配置,如下:
<build>
<finalname>simple-webapp</finalname>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-war-plugin</artifactid>
<version>2.1.1</version>
<configuration>
<webxml>webcontent\web-inf\web.xml</webxml>
</configuration>
</plugin>
</plugins>
</build>