Eclipse中使用Maven創建Dynamic web module爲2.5的Java web項目

簡單描述

在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的項目

  1. 修改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>
  1. 在項目名上右鍵,選擇build path,修改JRE爲1.8版本
  2. 在項目名上右鍵 -> Properties -> Project Facets,在上面是修改不了 Dynamic Web Module,會報衝突。用下面的步驟修改
  3. 直接修改項目路徑下的.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>
  1. 最好是修改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>
  1. 右鍵項目名,使用Maven -> Update Project時,如果把JRE修改爲1.5,需要再次使用步驟2調整下
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章