1.執行環境相關-eclipse
阿新 • • 發佈:2018-11-16
1-配置maven
- 新增本地maven進eclipse:Window - Preference - Maven - Installations - Add
- 配置maven設定:Window - Preference - Maven - UserSettings
- 配置本地倉庫地址:進入maven的根目錄 - setting.xml,然後新增
<localRepository>D:\apache-maven-3.5.4\repository</localRepository>
2-新增和應用JRE
- Window - Preference - Java - Installed JREs
3-剛建立的maven專案提示JRE版本不對
- 在pom.xml中的build -> plugins中新增:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF8</encoding> </configuration> </plugin>
4-為test資料夾建立resources資料夾(可選,只為符合maven專案的標準)
- 在左側專案區新增資料夾
- 右鍵專案 - Build Path - Comfigure Build Path - Java Build Path - Source - Output folder,如果列表中沒有我們剛才建立的那個資料夾則點選右側的Add Folder新增進來。然後複製test/java的Output folder路徑貼上到test/resources的Output folder中
5-更改Dynamic Web Module,以提高動態解析js以及dom元素等的效能
- 右鍵專案 - Build Path - Comfigure Build Path - Project Facets - Dynamic Web Module 這裡雖然可以選擇版本,但是不能儲存,這算是eclipse一個小bug
- 右鍵專案 - Build Path - Comfigure Build Path - Resource 中可以看到本專案的地址,根據這個地址進入專案資料夾
- 在專案根目錄裡有一個.settings資料夾,使用Nodepad++編輯,將其中的
<installed facet="jst.web" version="2.3"/>
改為
<installed facet="jst.web" version="3.1"/>
然後儲存 - 回到eclipse,右鍵專案 - Refresh。再次檢視會發現Dynamic Web Module的版本已經改為了我們想要的。
6-修改web.xml約束
- 由於修改了Dynamic Web Module的版本號,所以WEB-INF中的web.xml檔案的DOCTYPE標籤的內容也要改成相對應的版本:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<!-- 你的內容 -->
</web-app>
7-更改編碼格式
- 專案的編碼:右鍵專案 - Build Path - Comfigure Build Path - Resource - Text file encoding選擇other中的utf-8
- 修改tomcat處理get請求的編碼:在tomcat安裝目錄 - conf - server.xml的Connector標籤裡,新增
URIEncoding="UTF-8"
:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
- 又因為eclipse內部有整合tomcat容器,所以經過了第2步的修改會發現在除錯get請求的時候還是會有亂碼出現,這時候需要修改eclipse中的tomcat配置。點選右側Project Explorer中Servers前面的三角箭頭,展開後選擇你要修改的Tomcat會發現有一個server.xml,把第二步修改的內容再次修改即可。
8-設定預設載入頁面
- 在WEB-INF的web.xml檔案中新增:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>