天天看點

将struts源碼導入eclipse

預制條件和spring源碼導入eclipse中一樣,下面直接給出導入eclipse的步驟。

步驟:

1. 下載下傳struts相應版本的源碼 

 http://struts.apache.org/download.cgi

 。我這裡下載下傳的是struts-2.3.16-all.zip。下載下傳完成後解壓到本地目錄。

2. struts的源碼是通過maven管理的,是以需要下載下傳maven 

http://maven.apache.org/download.cgi  。下在完成後同樣解壓到本地目錄,然後配置MAVEN_HOME、PATH環境變量。如果配置正确的話在cmd中輸入:mvn -v 能夠正确顯示其版本号。此外需要修改本地倉庫的位置:修改 %MAVEN_HOME%/conf/settings.xml檔案,在settings中間配置repository:
将struts源碼導入eclipse
将struts源碼導入eclipse

1 settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
 2           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 3           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 4   <!-- localRepository
 5    | The path to the local repository maven will use to store artifacts.
 6    |
 7    | Default: ${user.home}/.m2/repository
 8   <localRepository>/path/to/local/repo</localRepository>
 9   -->
10     <localRepository>E:/Maven/apache-maven-3.1.1/repositories</localRepository>
11 .........      

settings.xml

該目錄其實就是指定本地倉庫的位置,也就是後續通過maven下載下傳的包預設都放到該路徑下。

3. 進入struts源碼根路徑下的src檔案夾,可以看到一個pom檔案。其實我們這時候就可以直接打開控制台輸入: mvn eclipse:eclipse 來進行編譯。不過這樣後面會碰到編譯失敗的問題,分析後發現其實需要注釋掉兩個地方,一個是src檔案夾下的pom.xml檔案中:

将struts源碼導入eclipse
将struts源碼導入eclipse
1 <modules>
2         <module>xwork-core</module>
3         <module>core</module>
4         <module>apps</module>
5         <module>plugins</module>
6        <!-- 注釋掉這兩個子子產品 -->
7         <!--<module>bundles</module>
8         <module>archetypes</module>-->
9     </modules>      

src/pom.xml

一個是src/app/pom.xml中:

将struts源碼導入eclipse
将struts源碼導入eclipse
1 <modules>
2         <module>blank</module>
3        <!-- 注釋掉這個子產品 -->    
4        <!-- <module>jboss-blank</module> -->
5         <module>mailreader</module>
6         <module>portlet</module>
7         <module>showcase</module>
8         <module>rest-showcase</module>
9     </modules>      

src/app/pom.xml

注釋掉之後在src目錄下打開控制台輸入: mvn eclipse:eclipse 即可。

4. eclipse需要安裝maven插件。可以在eclipse的 help--->marketplace中搜尋maven,然後安裝如下版本即可:

将struts源碼導入eclipse

安裝完成之後,打開 windows--->preferences,搜尋maven,配置instalations為MAVEN_HOME和user settings為MAVEN_HOME/conf/settings.xml即可:

将struts源碼導入eclipse
将struts源碼導入eclipse

4. 編譯完成之後即可在eclipse中進行導入。實際上我們隻需導入: core 和 xwork-core兩個工程即可,其他工程用不到。

接下來就可以随意的對struts源碼進行調試了。

黎明前最黑暗,成功前最絕望!

繼續閱讀