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文件找不到的问题
原文地址:https://www.cnblogs.com/codething/p/8502685.html