eclipse 搭建 springmvc 框架

搭建一個maven項目,mvc架構,web端使用springmvc,主要記錄下搭建時遇到的問題

1.主pom.xml文件語句 名稱爲hibeauty-modules
java

mvn archetype:generate -DgroupId=com.hibeauty -DartifactId=hibeauty-modules -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

此時須要進入pom,把package改成pom,這樣纔會把此pom做爲主pomweb

<packaging>pom</packaging>


進入目錄,分別創建webapp項目以及普通的maven項目。

進入到hibeauty-modules,運行如下命令,項目爲名稱爲hibeauty-web,這是一個webapp項目,以後要單獨處理一下。

spring

mvn archetype:generate -DgroupId=com.hibeauty -DartifactId=hibeauty-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false




web依賴的service的名稱爲hibeauty-business,進入到hibeauty-modules,運行如下命令,這是一個普通maven項目
tomcat

mvn archetype:generate -DgroupId=com.hibeauty -DartifactId=hibeauty-business -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false



注意:此時的webapp項目運行mvn eclipse:eclipse並不能被eclipse承認爲一個web項目,也就是說你的eclipse裏的tomcat不能認出這個web項目,須要運行的是
架構

mvn eclipse:eclipse -Dwtpversion=2.0


另外,若是須要下載對應jar包的源碼,須要運行
mvc

mvn eclipse:eclipse -DdownloadSource=true




2.在主pom對應的文件夾裏運行 mvn clean install eclipse:eclipse 這樣就完成了pom文件中的jar包下載,而且生成了eclipse的對應加載文件,使eclipse可以認出兩個bundle了

3.進入到eclipse裏面,在tomcat裏面導入webapp項目,而後再server裏面運行,若是報錯的內容是找不到相似於

app

org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: 
org.springframework.web.context.ContextLoaderListener

Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener


這樣,可是若是你在java build path的lib裏面又能看到這些包,就須要把這些文件從java build path裏面複製到Deployment Assembly裏面。具體方法properties->Deployment Assemble->Add->java build path 便可解決。同理若是出現找不到依賴的project的錯誤,properties->Deployment Assemble->Add->project引進來便可

最後,此次框架搭建,我分別用了intellij idea 以及eclipse , 個人感受是idea適合搭建框架,由於他對xml文件的支持很好,會自動去找引入的java文件是否存在並提示用戶,這方面eclipse就比較弱。另外idea的maven支持很好,對於框架搭建的環境要求很低,不少環境配置他自動幫你作了,好比上面的1,2,3步驟,都是針對eclipse的作法。另外idea還有個很牛的圖示類依賴關係的功能。

可是在代碼開發時,eclipse是一個不錯的選擇。
1 .他有方便的快捷鍵
2 .svn比idea強,尤爲是在增長刪除文件的時候。
3 .讓我開發時堅決選擇eclipse的主要緣由是eclipse的報錯機制很強,在左邊的package     explorer能夠很清楚的看到出現的錯誤,固然,前提是開啓了build automatically,而且比idea顯眼的多
4 .idea不會把當前文件跟左邊的目錄自動對應,即便打開了那個roll的開關也會常常出問題。

因此,我建議架構師用idea,開發人員用eclipse框架

相關文章
相關標籤/搜索