Maven工程时添加的war包war 报错
在创建Maven工程时,添加的war包工程中,<packaging>war</packaging>会报错,并且错误没有提示信息。
原因:src/main/webapp下面缺少WEB-INF/web.xml文件
解决方案1:在工程中需要添加一个文件,如下图所示:在工程的src下的main文件下的webapp文件下建立新文件夹WEB-INF文件夹,然后在该文件夹下添加web.xml 文件。
添加完web.xml文件后,在web.xml中写入如下内容:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="******" version="2.5">
- <display-name>******-manager</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
注意:上述代码中的*是项目的名称,根据你建立的web.xml自动生成,你所要添加的就是<welcome-file-list>中的内容。
解决方案2:右键项目--》java EE Tools--》Generate Deployment Descriptor Stub,则会自动创建WEB-INF/web.xml
添加完毕后,还要右键工程,选择Maven,选择Update Project...更新一下工程,此时错误就会消失。
还可以在webapp文件下写一个测试网页如:index.jsp,验证Maven工程是否能正常运行。