简单描述
在Eclipse中创建Maven web项目时,使用maven-archetype-webapp 1.0创建的web项目,默认是2.3版本。
web.xml文件内容如下
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
操作步骤
通过一些操作,可以将该项目转为web 2.5的项目
- 修改web.xml的内容如下,修改为2.5的模板
<?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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Archetype Created Web Application</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>
- 在项目名上右键,选择build path,修改JRE为1.8版本
- 在项目名上右键 -> Properties -> Project Facets,在上面是修改不了 Dynamic Web Module,会报冲突。用下面的步骤修改
- 直接修改项目路径下的.settings\org.eclipse.wst.common.project.facet.core.xml文件,改为下面的配置,然后保存
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>
- 最好是修改pom.xml文件,添加下面这一段:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
- 右键项目名,使用Maven -> Update Project时,如果把JRE修改为1.5,需要再次使用步骤2调整下