创建maven web项目 pom报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war

来源:互联网 发布:软件销售企业财务处理 编辑:程序博客网 时间:2024/06/05 21:03


一、新建一个maven项目:
1、pom报错:

2、报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project withmaven3: 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

3、分析:没有web.xml文件。

在网上找了个方法,终于解决了:

http://blog.csdn.net/stemq/article/details/52922790

下面的是复制过来的:

问题现象:

用Maven打包时,报Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war错误。

原因分析:

打包时在WebContent/WEB-INF/文件夹下找不到web.xml文件。

解决方案:

如果WebContent/WEB-INF/web.xml文件存在,需要在pom.xml文件的<build>节点中,加上maven-war-plugin插件配置。

[plain] view plain copy
  1. <plugins>  
  2.     <plugin>  
  3.         <groupId>org.apache.maven.plugins</groupId>  
  4.         <artifactId>maven-war-plugin</artifactId>  
  5.         <version>3.0.0</version>  
  6.         <configuration>  
  7.             <webResources>  
  8.                 <resource>  
  9.                     <directory>WebContent</directory>  
  10.                 </resource>  
  11.             </webResources>  
  12.         </configuration>  
  13.     </plugin>  
  14. </plugins>  

如果WebContent/WEB-INF/web.xml文件不存在,则按下面的方式配置。

[plain] view plain copy
  1. <plugins>  
  2.     <plugin>  
  3.         <groupId>org.apache.maven.plugins</groupId>  
  4.         <artifactId>maven-war-plugin</artifactId>  
  5.         <version>3.0.0</version>  
  6.         <configuration>  
  7.             <failOnMissingWebXml>false</failOnMissingWebXml>  
  8.         </configuration>  
  9.     </plugin>  
  10. </plugins>  
4、最后:

1、右键项目,然后run as -》maven clear -》maven builder 或者直接:
maven -》 update project 选中 


然后就ok了。





阅读全文
0 0
原创粉丝点击