Maven 打包出现 Error assembling WAR: webxml attribute is required 错误

本文将介绍怎样解决在 Maven 打包过程中抛出的 “Error assembling WAR: webxml attribute is required” 错误。

下面是使用 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 文件呢?

普通 Maven 项目

打包 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 程序

由于 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 仓库就可以了。

学习,学习,再学习!学,然后知不足。 —— 列宁
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号