(1)創建maven項目,選擇web骨架。
(2)填寫項目名
(3)選中項目/ alt+enter / Project Facets / 點Convert to faceted form
(4)勾選Dynamic後,點擊Further Configuration【如過servlet是2.5版本的,請看本章步驟(9)】
(5)將Content directory寫成 src/main/webapp
(6)接下來修改web.xml的版本。默認版本是2.3,這裏我改成3.0
(7)複製以下代碼替換掉老的,如下圖
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>webw</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>
(8)報錯如下:意思是編譯器版本不兼容
複製以下代碼到pom.xml中,如下圖
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
(9)修改Dynamic版本爲3.0。找到本地workspace中的當前項目,打開org.eclipse.wst.common.project.facet.core.xml,修改如下圖。
(10)直接部署,訪問默認index.jsp