1. 程式人生 > >idea中添加web.xml配置文件與tomcat啟動中遇到的web.xml文件找不到的問題

idea中添加web.xml配置文件與tomcat啟動中遇到的web.xml文件找不到的問題

解決 目的 信息 需要 遇到 技術分享 maven打包 ima clas

1,如何在idea中向war項目中添加web.xml的配置文件

idea通過maven創建war項目時沒有指定是webapp導致創建出來的項目沒有webapp的文件夾。其實war項目中都是在"項目名/src/main"目錄下技術分享圖片

只要在這個項目下創建webapp/WEB-INF/web.xml就行了

2,如果你沒有把web.xml放在"項目名/src/main/webapp/WEB-INF/web.xml",這時tomcat啟動就會報錯:

maven打包時錯誤信息:Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)


原因:

maven打包web項目默認的webroot是在src\main\webapp。如果在此目錄下找不到web.xml就拋出以上的異常。

解決辦法:需要在pom.xml中增加<webResources>配置,如下:

 1   <plugin>
 2                 <groupId>org.apache.maven.plugins</groupId>
 3                 <artifactId>maven-war-plugin</artifactId>
 4                 <version>2.1.1</version>
 5
<configuration> 6 7 <webXml>src\webapp\WEB-INF\web.xml</webXml> 8 9 </configuration> 10 </plugin>

這裏的<webXml>裏面的位置時相對於項目的路徑的,上級是項目名的目錄那級:

web.xml的路徑是

項目名\src\webapp\WEB-INF\web.xml

idea中添加web.xml配置文件與tomcat啟動中遇到的web.xml文件找不到的問題