Java:Failed to execute goal org.apache.maven.plugins:maven-war-plugin
可能有3个原因导致出现该问题:
1、项目中没有 src/main/webapp/WEB-INF/web.xml 文件;
2、有了上述文件,但是没在pom.xml中说明这个文件的位置;
3、以上两个都有,但是 pom.xml 中的插件maven-war-plugin的版本不对;
两种解决方法:
1、有web.xml文件的前提下,解决步骤(2022年6月版本):
①首先要保证有web.xml文件,且文件在src/main/web/WEB-INF目录下,有时可能会因为不小心把web和main放在同级目录下而出错;
②在pom.xml中说明WEB-INF的位置,写法如下:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> <configuration> <webResources> <resource> <directory>src/main/webapp</directory> </resource> </webResources> </configuration> </plugin> </plugins> </build>
③注意maven-war-plugin的版本,之前我用3.0.0版本就会报错,用3.2.1版本就不会报错
2、没有web.xml文件的前提下,解决步骤(2022年6月版本):
现在我们的文件结构下,没有web.xml文件了
①在pom.xml中说明插件maven-war-plugin
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> </plugin> </plugins> </build>
②在<properties>块中说明忽略了web.xml文件:
<properties><failOnMissingWebXml>false</failOnMissingWebXml> </properties>
即可