一、準備工作
1、下載appfuse-dependencies-2.0.2.zip和appfuse-documentation-2.0.2.pdf
https://appfuse.dev.java.net/servlets/ProjectDocumentList?folderID=9173&expandFolder=9173&folderID=4695
下載apache-maven-2.0.9-bin.zip
http://maven.apache.org/download.html
2、配置環境變量JAVA_HOME(JDK 5+)、MAVEN_HOME(2.0.9+),安裝MySQL 5.x數據庫。
二、構建官方指南
1、為了加快構建時間,可以提前下載相應的軟件。除了appfuse-dependencies-2.0.2.zip外,還需要下載apache-tomcat-6.0.14.zip。
appfuse-dependencies-2.0.2.zip解壓到C:\Documents and Settings\Administrator\.m2\repository
apache-tomcat-6.0.14.zip拷貝到C:\Documents and Settings\Administrator\Local Settings\Temp\cargo\installs
2、開始構建,建立目錄appfuse,在命令窗口進入到目錄中,執行C:\appfuse>mvn
archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts
-DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.2
-DgroupId=com.mycompany.app -DartifactId=myproject 運行此命令是為了構建基于struts2的appfuse項目。在appfuse目錄下生成myproject目錄及相關文件。
然后在確認通過用戶名為root、密碼為空進入mysql的情況下,執行:C:\appfuse\myproject>mvn 運行此命令會完成相關 jar 包和 Tomcat 的下載,并運行工程的集成測試。
最后可以通過執行C:\appfuse\myproject>mvn
jetty:run-war ,你就可以去查看你的工程了。用這個地址:http://localhost:8080在你的瀏覽器中查看你的工程,管理員的默認用戶名/密碼為 admin/admin ,普通用戶的話,可以用 user/user 登錄。
3、通過執行C:\appfuse\myproject>mvn appfuse:full-source可以看到appfuse2.0的源碼,通過執行C:\appfuse\myproject>mvn可以建立適合eclipse環境的工程,不過直接導入工程文件后會有很多地方報錯,需要在eclipse中重新配置后才可以使用。
三、構建自己的工程
1、創建工程(基于struts2)
C:\appfuse>mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes
-DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/releases
-DarchetypeVersion=2.0.2 -DgroupId=com.mycompany.app -DartifactId=myproject
2、修改數據庫相關信息(我用的是sql server),進入myproject打開pom.xml文件,在文件底部修改數據庫信息。并修改genericCore屬性為false(若生成dao、service等類需要修改此屬性)。
3、由于有現成的數據庫所以直接生成實體類,執行:mvn appfuse:gen-model命令,在myproject\src\com\mycompany\app\model下生成了相應的文件。
4、生成dao、service等類,執行:mvn
appfuse:gen -Dentity=pojoName。雖然dao、service等類都生成了,但在構建時報了些信息但并沒有標明是錯誤:
[INFO] [appfuse:gen]
Property
'http://apache.org/xml/features/nonvalidating/load-external-dtd' is not
recognized.
org.xml.sax.SAXNotRecognizedException: Property
'http://apache.org/xml/features/
nonvalidating/load-external-dtd' is not recognized. at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.getProperty(AbstractSAXParser.java:2060)
貌似解析xml時出現了不認可的屬性。根據http://www.nabble.com/errors-with-appfuse:gen-td17424029s2369.html說明,可能以后使用中會出現其他錯誤,建議使用appfuse2.0.1版本。