【maven 報錯】maven項目執行maven install時報錯Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)


 

在使用maven新建的web項目中,執行

 

執行如上的這兩個操作,報錯:

 1 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project bioligyInfo: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_73\..\lib\tools.jar -> [Help 1]
 2 [ERROR] 
 3 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 4 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 5 [ERROR] 
 6 [ERROR] For more information about the errors and possible solutions, please read the following articles:
 7 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
 8 
 9 
10 
11 
12 
13 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project bioligyInfo: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
14 [ERROR] 
15 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
16 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
17 [ERROR] 
18 [ERROR] For more information about the errors and possible solutions, please read the following articles:
19 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
View Code

上面的兩種錯誤,提示的很明顯:

錯誤1:

 

其實不用從maven下載插件,只需要保證你的pom.xml文件中有如下的信息即可:

 1  <build>
 2       <plugins>
 3           <plugin>
 4               <artifactId>maven-war-plugin</artifactId>
 5               <configuration>
 6                   <version>2.5</version>
 7               </configuration>
 8           </plugin>
 9       </plugins>
10   </build>
11   
12   <properties>                                                                                                
13        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>                                  
14        <spring.version>4.1.4.RELEASE</spring.version>                                                      
15        <hibernate.version>4.3.8.Final</hibernate.version>                                                  
16        <jackson.version>2.5.0</jackson.version>                                                            
17                                                                                                            
18    </properties>  
View Code

 

錯誤2:

 

 提示找不到web.xml文件

解決方法:

1》如果你沒有配置web.xml文件,那就創建web.xml文件

2》如果你配置了web.xml文件,還有這樣的錯誤,那就是你的web.xml文件不能被你項目讀取到

如下,項目中web.xml的位置如下:

 

而我們需要讓項目讀取到它:

因為web.xml文件的路徑如下:src\main\webapp\WEB-INF\web.xml

 

如果依舊無法解決,那就在pom.xml文件中配置如下:

 1   <build>
 2       <plugins>
 3           <plugin>
 4               <artifactId>maven-war-plugin</artifactId>
 5               <configuration>
 6                   <version>2.5</version>
 7               <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
 8               </configuration>
 9           </plugin>
10       </plugins>
11   </build>
View Code

這樣指定到具體的文件上  就可以解決這問題了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM