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 > 配置, 如下:
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.1.1</version>
- <configuration>
- <webXml>src\webapp\WEB-INF\web.xml</webXml>
- </configuration>
- </plugin>
这里的 < webXml > 里面的位置时相对于项目的路径的, 上级是项目名的目录那级:
web.xml 的路径是
项目名 \ src\webapp\WEB-INF\web.xml
来源: http://www.bubuko.com/infodetail-2514333.html