1. 程式人生 > >Myeclipse學習總結(15)——Eclipse/MyEclipse中Maven專案常見問題解決彙總

Myeclipse學習總結(15)——Eclipse/MyEclipse中Maven專案常見問題解決彙總

Eclipse/MyEclipse中Maven專案一般會遇到如下問題:

一. The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 錯誤

這是eclipse環境裡沒有SeverRuntime導致的,在BuildPath里加入即可,如下圖,新增前:


選擇 add library


選擇 Apache Tomcat V7.0 並點選 next


點選finish之後,完成新增如下圖


二. 如何Maven建立動態Web專案後產生的版本不匹配的問題
我們用Eclipse建立Maven結構的web專案的時候選擇了Artifact Id為maven-artchetype-webapp,由於這個catalog比較老,用的servlet還是2.3的、java版本是1.5的,而一般現在至少都是3.0/1.7,因此我們需要逐個修改!

(1) 修改JRE 版本

Go to project Build Path and change the Java Library version to 1.7


刪除原先的低版本JRE,並新增workplace預設的版本(JDK1.7),完成後如下:


(2) Eclipse Preferences -> Java -> Compilre -> Change compliance level to 1.7


(3) 修改 Project Facets 版本(注意順序)

在專案上單機右鍵 -> Properties -> Project Facets -->取消選中 Dynamic Web Module 狀態,點選 Apply -->將 Java facet 版本變為 1.7 ,點選 Apply如下圖


-->將 Dyanmic Web Module 版本更改為3.0, 點選 Apply.


此時會有較大機率提示: web.xml is missing and <failOnMissingWebXml> is set to true,如下圖


解決辦法,在專案上單擊右鍵-->java EE Tools ---> Generate Deployment Descriptro Stub


OK 問題解決
三. 解決釋出之後404錯誤

預設情況下因為預設的deployment assembly中 webapp路徑的問題,如下圖可以看到預設的webapp下的頁面都被髮布到WEB-INF/class下了,


導致出現瞭如下圖的目錄結構,所以所有的jsp都無法訪問以及通過web.xml載入的ssm環境無法初始化!


Eclipse配置maven web專案的所有問題總結
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'
出現SetPropertiesRule警告的原因是因為Tomcat在server.xml的Context節點中不支援source屬性:<Context docBase="…" path="/…" source="org.eclipse.jst.j2ee.server:…"/>
解決方法是在Servers視圖裡雙擊建立的server,然後在其server的配置介面中選中"Publish module contexts to separate XML files"選項。
具體“Publish module contexts to separate XML files”是什麼意思,
請看Tomcat Publishing Options介紹:
Two new options which affect publishing are now available in the Server Options section of the Tomcat server editor. The Tomcat server must be 5.0.x or later for these options to be enabled. The Serve modules without publishing option does what it says. Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader. The Publish module contexts to separate XML files option will publish contexts using the preferred method of separate XML files under the "conf/Catalina/localhost" directory, rather than keeping them in the "server.xml" file. A couple of improvements for this option are noted in Bugs 180931 and 180936.
關於解決方法,再詳細說明一下:
Servers檢視的開啟方法:Window--Show View-other..--Servers
雙擊Server:就是雙擊伺服器名,我的伺服器名為:Tomcat v6.0 Server at localhost 即雙擊它,進入
server的配置介面: 選中"Publish module contexts to separate XML files"選項
web.xml is missing and <failOnMissingWebXml> is set to true解決方法
這種錯誤是因為maven預設簡單構建專案是sevlet3.0版本,web.xml不是必須的,這時候需要手動建立webapp/WEB-INF/web.xml,web.xml可以從其他專案複製一個過來改改,

或者pom.xml新增如下配置


修改完了別忘了右鍵專案Mavan/update project..