clipse建立Maven結構的web項目的時候選擇Artifact Id爲maven-artchetype-webapp,點擊finish以後,通常會遇到以下問題java
1. The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 錯誤,web
這是eclipse環境裏沒有SeverRuntime致使的,在BuildPath里加入便可,以下圖:apache
添加前:服務器
選擇 add libraryapp
選擇 Apache Tomcat V7.0 並點擊 nexteclipse
點擊finish以後,完成添加以下圖webapp
2. 如何Maven建立動態Web項目後產生的版本不匹配的問題jsp
咱們用Eclipse建立Maven結構的web項目的時候選擇了Artifact Id爲maven-artchetype-webapp,因爲這個catalog比較老,用的servlet仍是2.3的、java版本是1.5的,而通常如今至少都是3.0/1.7,所以咱們須要逐個修改!maven
(1) 修改JRE 版本ui
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 問題解決
3. 解決發佈以後404錯誤
默認狀況下由於默認的deployment assembly中 webapp路徑的問題,以下圖能夠看到默認的webapp下的頁面都被髮布到WEB-INF/class下了,
致使出現了以下圖的目錄結構,因此全部的jsp都沒法訪問以及經過web.xml加載的ssm環境沒法初始化!
出現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"選項
這種錯誤是由於maven默認簡單構建項目是sevlet3.0版本,web.xml不是必須的,這時候須要手動建立webapp/WEB-INF/web.xml,web.xml能夠從其餘項目複製一個過來改改,
或者pom.xml添加以下配置
<build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </pluginManagement> </build>
修改完了別忘了右鍵項目Mavan/update project..