1,如何在idea中向war項目中添加web.xml的配置文件web
idea經過maven建立war項目時沒有指定是webapp致使建立出來的項目沒有webapp的文件夾。其實war項目中都是在"項目名/src/main"目錄下apache
只要在這個項目下建立webapp/WEB-INF/web.xml就好了tomcat
2,若是你沒有把web.xml放在"項目名/src/main/webapp/WEB-INF/web.xml",這時tomcat啓動就會報錯:app
maven打包時錯誤信息:Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)webapp
緣由:maven
maven打包web項目默認的webroot是在src\main\webapp。若是在此目錄下找不到web.xml就拋出以上的異常。ide
解決辦法:須要在pom.xml中增長<webResources>配置,以下:ui
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>裏面的位置時相對於項目的路徑的,上級是項目名的目錄那級:idea
web.xml的路徑是spa
項目名\src\webapp\WEB-INF\web.xml