通過Appfuse2來快速建立開發框架(2) --建立本地開發環境

1、下載
JDK5(jdk5su13)
Maven 2.0.5+ (maven2.0.8)
Tomcat 5.5+ (tomcat6.0)
Eclipse 3.3+
MyEclipse 6.0+(可選)
TortoiseSVN 1.4.5+
MySQL GUI Tools 5.0(可選)

2、安裝 
 2.1、基本安裝
安裝前需要確認已安裝 winzip 或 winrar 用來解壓文件。
安裝順序:TortoiseSVN, JDK,Maven, Tomcat, Eclipse, MyEclipse,MySQL GUI Tools
推薦安裝目錄:假定根目錄爲D: (實際可能爲D: E: F: 等)

D:/DevEnv
JDK
jdk1.5
Tool 工具包
Maven-2.0.8
Eclipse3.3
MyEclipse6.0
MySQL GUI Tools 5.0
TortoriseSVN1.4.5
Server 服務器
apache-tomcat-5.5.23
repository maven本地庫

DevEnv Document Projects 不是必須在同一個根目錄下

2.1、Eclipse插件
WTP
參見 Eclipse Web Tools Project
Spring Support
Spring IDE
參見安裝Spring IDE site name=Spring IDE updatesite
url=http://springide.org/updatesite/
更多細節,請參見 http://appfuse.org/display/APF/Eclipse

SVN eclipse plugin
http://subclipse.tigris.org/ Subclipse updatesite
http://subclipse.tigris.org/update_1.2.x
Maven2 插件
http://m2eclipse.codehaus.org/ M2eclipse updatesite
http://m2eclipse.codehaus.org/update/
http://maven.apache.org/eclipse-plugin.html

Eclipse update site URL
http://q4e.googlecode.com/svn/trunk/updatesite/

3、配置
3.1、環境變量設置
DEV_HOME=D:/DevEnv
JAVA_HOME=%DEV_HOME%/JDK/jdk1.5
M2_HOME=%DEV_HOME%/Tool/Maven-2.0.8
CATALINA_HOME=%DEV_HOME%/Server/apache-tomcat-5.5.23
PATH=%JAVA_HOME%/bin;%M2_HOME%/bin;%CATALINA_HOME%/bin;%PATH%
設置好環境變量後在Dos命令行鍵入"java -version", "mvn -version"確認已安裝正確。

3.2、SVN本地配置
設置全局忽略樣式 (文件瀏覽器-〉鼠標右鍵-〉TortoriseSVN—〉設置-〉常規設置)

target *.jar *.class *.log *.bak

3.3、maven2配置
開發通過Maven2來使用統一中心類庫,需要修改Maven2的配置

修改%M2_HOME%/conf/settings.xml文件

<settings>
<localRepository>${DEV_HOME}/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<servers>
<server>
<id>vs-repo</id>
<username>vsuser</username>
<password>veryservice</password>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<mirrorOf>*</mirrorOf>
<url>http://manage.veryservice.com/artifactory/repo</url>
<name>Artifactory</name>
</mirror>
</mirrors>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>central</id>
<url>http://xxx.com/artifactory/repo</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://xxx.com/artifactory/repo</url>
<releases><enabled>false</enabled></releases>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
修改${user.home}/.m2/settings.xml文件(C:/Documents and Settings/${user.name}/.m2/settings.xml)

<settings/>

3.4、Eclipse(MyEclipse)配置
設置Eclipse的workspace到D:/Projects(參見安裝中設置的工程目錄)

mvn -Declipse.workspace=D:/Projects eclipse:add-maven-repo
同時設置Eclipse項目中環境變量 M2_REPO=${DEV_HOME}/repository

4、使用
4.1、新建工程

新建Maven2工程(使用Appfuse2)
基於Struts2的Web工程
Web Struts2 mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.web -DartifactId=web


後臺應用工程
Core(backend) mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-core -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.framework -DartifactId=framework


帶struts2的模塊工程
Struts Module mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-modular-struts -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.xxx.framework -DartifactId=framework

4.2、maven配置修改
修改工程目錄下pom.xml文件

修改數據庫設置:
(更改數據庫名、用戶名和密碼)

<!-- Database settings -->
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>
<![CDATA[jdbc:mysql://localhost/testdb?useUnicode=true&characterEncoding=utf-8]]>
</jdbc.url>
<jdbc.username>user</jdbc.username>
<jdbc.password>password</jdbc.password>

修改配置支持JPA:
<!--<dao.framework>hibernate</dao.framework>-->
<dao.framework>jpa</dao.framework>
//hibernate3-maven-plugin   如果module方式,則修改core目錄下的pom.xml
</!--<implementation>annotationconfiguration</implementation>-->
<implementation>jpaconfiguration</implementation>

修改代碼以及doc包下載方式 根目錄下pom.xml
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>

JPA配置文件在src/main/resources/META-INF/persistence.xml

4.3 獲取Appfuse源代碼
mvn appfuse:full-source

4.4 將Maven2工程轉換爲Eclipse工程
在項目文件中執行 mvn eclipse:eclipse //
mvn install eclipse:eclipse //module方式
生成Eclipse項目文件

4.5 Eclipse IDE中導入新項目
Eclipse和MyEclipse操作基本相同
基本框架代碼編譯
此步驟會生成數據相關的表 mvn test-compile
hibernate.hbm2ddl.auto=none|validate|create|create-drop|update

4.6 運行測試新項目
進入項目web目錄 執行,如果沒有報錯,則表示appfuse項目創建成功 mvn jettty:run-war

4.7 core項目設置
右鍵core 選擇properties 點擊java build path 選擇libraries將maven2 加入的變量去除

4.8 webapp項目修改
右鍵webapp選擇properties 點擊java build path 選擇libraries將maven2 加入的變量去除
source下,將webapp/src/main/webapp去除
色sourcre下,添加目錄target/
Unknown macro: {項目名稱}
-1.0-SNAPSHOT/WEB-INF/lib,並設置輸出路徑爲src/main/webapp/WEB-INF/lib
在該項目上點右鍵MyEclipse->Add Web Capabilities->修改Web root地址(點【瀏覽】按鈕指定爲當前工作空間下的src/main/webapp文件夾)

4.9 將webapp上帶紅點的文件,設置爲不檢查
在該項目上點右鍵 properties -> myeclipse -->validation 確保不要將override validation perferences選中.excluded resources 將不檢查的文件勾中 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章