前些天花了很久才把a(bǔ)ppfuse2.0的demo運(yùn)行出來
都怪自己maven不熟悉啊
下載appfuse2.0源碼有兩種方法
一種是找到他的cvs下載。
還有一種就是用maven下載,就是appfuse2.0官網(wǎng)上介紹的下載方法。
好了,現(xiàn)在我們開始下載appfuse2.0的源碼,用第二鐘方法:
1、下載安裝 JDK5 或以上版本。
2、下載安裝 Mysql5.x 。
3、建立一個(gè)本地的 stmp服務(wù)器,或者修改 mail.properties(在 src/main/resources 目錄下),使之使用另外一個(gè)不同的主機(jī)名,它默認(rèn)是使用的主機(jī)名是 "localhost"。(這一步如果不是急需可以先省略,等對(duì)appfuse2.0熟悉些了再配置)
4、下載并安裝
Maven 2.0.6 。這個(gè)是必須的。有人問說不下載這個(gè)行不行?,我們build時(shí)用ant。在appfuse2.0中ant已經(jīng)不推薦使用了,所以這個(gè)是必需的。
簡(jiǎn)單介紹一下maven的使用,在網(wǎng)址http://maven.apache.org/download.html下載maven。
在Windows 2000/XP中使用
- 解壓 maven-2.0.6-bin.zip到你希望安裝Maven 2.0.6的目錄下. 例如 C:\Program Files\Apache Software Foundation\maven-2.0.6
- 在你的環(huán)境變量path中設(shè)置maven的路徑, 在我的電腦上右鍵選屬性, 選擇 "高級(jí)" tab, 在 "環(huán)境變量" ,新建一個(gè)MAVEN_HOME 例如C:\Program Files\Apache Software Foundation\maven-2.0.6。在path中設(shè)置%MAVEN_HOME%bin; 。也可以直接在path設(shè)置. "C:\Program Files\Apache Software Foundation\maven-2.0.6\bin";%PATH%
- 在你的環(huán)境變量中, 確認(rèn) JAVA_HOME 設(shè)置的是你本頂?shù)?JDK, 例如 C:\Program Files\Java\jdk1.5.0_02
- 打開:開始--運(yùn)行--敲入cmd。在命令行 執(zhí)行mvn --version ,如能正確顯示maven的版本號(hào),說明maven安裝成功。
如果你不喜歡用命令行的話,你也可以在eclipse創(chuàng)建自己的工程,你可以檢出 Candy for AppFuse
。
下面我們就可以下載appfuse2.0了,選擇你熟悉mvc,我下載的是Struts 2 Basic,
我在D:創(chuàng)建一個(gè)文件夾appfuse2-hzy,
例如D:\appfuse2-hzy\
在
命令行中輸入 mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/repository
-DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject
這時(shí)maven就開始創(chuàng)建項(xiàng)目了,maven首先在C:\Documents and
Settings\你的計(jì)算機(jī)用戶名\.m2\repository下載appfuse2.0所需要的jar文件,這是一個(gè)漫長(zhǎng)的等待過程。如果你的網(wǎng)速
極快,你可以等下去。在appfuse.java.net網(wǎng)站中appfuse作者已經(jīng)給我們準(zhǔn)備好appfuse2.0.m5-
dependencies.zip,你只要把它解壓到C:\Documents and
Settings\你的計(jì)算機(jī)用戶名\.m2\repository目錄里面maven檢測(cè)到就不用下載了。
下面是各種配置類型maven所使用的命令:
配置類型
|
命 令 |
JSF Basic |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-jsf -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Spring MVC Basic |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-spring -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Struts 2 Basic |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Tapestry Basic |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-tapestry -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
JSF Modular |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-modular-jsf -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Spring MVC Modular |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-modular-spring -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Struts 2 Modular |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-modular-struts -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Tapestry Modular |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-modular-tapestry -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
Core
(僅后端) |
mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-core -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app -DartifactId=myproject |
在maven執(zhí)行mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=
http://static.appfuse.org/repository
-DarchetypeVersion=2.0-m5 -DgroupId=com.mycompany.app
-DartifactId=myproject
時(shí),如果你的mysql數(shù)據(jù)庫(kù)已經(jīng)啟動(dòng)了,同時(shí)root用戶的密碼為空的話,appfuse會(huì)自動(dòng)在你的數(shù)據(jù)庫(kù)中生成一個(gè)myproject的數(shù)據(jù)庫(kù),
你的root用戶如果有密碼的話,你可以在你創(chuàng)建的項(xiàng)目的文件下的pom.xml中設(shè)置一下 <!-- Database settings -->
root
添加密碼
要運(yùn)行 AppFuse 現(xiàn)在已經(jīng)很容易了,一旦建立了項(xiàng)目原型,Maven會(huì)用hibernate3和dbunit的插件創(chuàng)建和生成數(shù)據(jù)庫(kù)。現(xiàn)在你要做的就是用 Maven 運(yùn)行 Jetty,然后查看你的工程。
1、 在命令行下,cd 到你的工程目錄下,運(yùn)行 mvn integration-test ,這個(gè)命令會(huì)完成相關(guān) jar 包和 Tomcat 的下載,運(yùn)行你的工程的集成測(cè)試。上面的命令大概需要5-10分鐘。
2、在你的工程目錄下運(yùn)行
mvn jetty:run-war ,你就可以去查看你的工程了。Maven 會(huì)啟動(dòng) Jetty,這樣的話,你就可以用這個(gè)地址:
http://localhost:8080在你的瀏覽器中查看你的工程了。(如果你使用的是模塊化原型,你需要在你的工程的 web 目錄下運(yùn)行
mvn jetty:run-war 。)
管理員的默認(rèn)用戶名/密碼為
admin/admin ,普通用戶的話,可以用
user/user 登錄。
運(yùn)行成功之后,你可能會(huì)打開appfuse的src查看源碼
發(fā)現(xiàn)src\main\java\com\hzy\app只有一個(gè)App.java再也沒別的文件了,不要著急。我們接著執(zhí)行如下命令mvn
appfuse:full-source.現(xiàn)在你終于可以看到appfuse2.0的源碼了,哈哈.在項(xiàng)目的src\main\java\下會(huì)多出一個(gè)
org的文件,一步步進(jìn)去
你會(huì)源碼就在這里。更多詳細(xì)細(xì)節(jié)請(qǐng)去官網(wǎng)扣英文字眼