下面是使用 Maven 打包 war 包时抛出的错误信息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project ***_server: 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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn-rf :***_server根据上面的错误信息可知,错误是因为没有配置 web.xml 文件导致的。那么,如何配置 web.xml 文件呢?
打包 war 项目,必须指向一个 web.xml 文件,没有就会报错。web.xml 文件的路径可配置,如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>webapps\WEB-INF\web.xml</webXml>
</configuration>
</plugin>由于 Spring Boot 不需要 web.xml 文件,可以加入以下配置,如下:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>说道 maven 打包问题,顺便说一个另外的 maven 打包问题,如果我们项目依赖了其他项目,但是其他项目没有使用私库发布项目,导致我们需要通过本地 maven 的方式依赖其他项目,打包过程可能出现如下错误:
The repository system is offline but the artifact com.***:***-parent:pom:1.0 is not available in the local repository导致该问题的原因是,其他项目没有将依赖安装到本地 maven 导致的,因此,需要先在其他项目中执行 maven install,将它安装到本地 maven 仓库就可以了。