軟件版本:
Eclipse:eclipse-jee-neon-3-win32-x86_64
JDK: 1.8
Openfire: 4.1.5
- 下載源碼

圖1.png
選擇openfire_src_4_1_5.zip下載
- 配置Eclipse項(xiàng)目。把下載好的 openfire_src_4_1_5.zip 壓縮包直接解壓到Eclipse的工作目錄(E:\eclipse\openfire),結(jié)構(gòu)如下:

圖2.png
- 打開openfire_src,目錄如下

圖3.png
將圖中的三個(gè)html文件刪除。
- 把openfire_src/build/eclipse/下的三個(gè)文件夾復(fù)制到openfire_src/目錄下。

圖4.png

圖5.png
- 把openfire_src目錄下的classpth文件、project文件、settings文件夾修改成Eclipse工程配置文件格式,重命名為在每個(gè)原有的名字上加上一個(gè)點(diǎn),即.classpth、.project、.settings。如下圖所示:

圖6.png
注意:在windows下面不能直接重命名,需要在dos下面操作,即進(jìn)入相應(yīng)的目錄執(zhí)行rename classpth .classpth即可,其它兩個(gè)文件執(zhí)行一樣的操作。

圖7.png
- 打開Eclipse,選擇 File –> Import… –> Existing Projects into Workspace 選擇E:\eclipse\openfire\openfire_src 導(dǎo)入即可

圖8.png
- 導(dǎo)入后目錄結(jié)構(gòu)如下(因源文件夾太多,截圖無(wú)法截全)

圖9.png
- 使用ANT進(jìn)行工程的編譯。Eclipse中Window->Show View->Ant,顯示出Ant窗口,單擊右鍵,在彈出的快捷菜單中選擇Add Buildfiles,在彈出的對(duì)話框中,展開openfire/build文件夾,選擇build目錄下的build.xml,點(diǎn)擊OK,接下來(lái)在Ant視圖中將Openfire XMPP Server右鍵選擇Run As->Ant Build,等待片刻,在控制臺(tái)中顯示“BUILD SUCCESSFUL” 那么就表示編譯成功。

圖10.png

圖11.png
- 設(shè)置啟動(dòng)項(xiàng)目。點(diǎn)擊openfire項(xiàng)目,在菜單欄中選擇Run->Run Configurations彈出一個(gè)對(duì)話框,在左側(cè)菜單中右鍵點(diǎn)擊Java Application,選擇New創(chuàng)建啟動(dòng)配置。

圖12.png
- 其中 Name隨便設(shè)置,Main class設(shè)置為"org.jivesoftware.openfire.starter.ServerStarter",點(diǎn)擊應(yīng)用。

圖13.png
- 點(diǎn)擊進(jìn)入Arguments選項(xiàng)卡,在上面那個(gè)框(VM arguments:)中填寫
-DopenfireHome="${workspace_loc:openfire}/target/openfire"
其中${workspace_loc:openfire} 中的 openfire要根據(jù)你的項(xiàng)目名來(lái)進(jìn)行同步修改,點(diǎn)擊Apply應(yīng)用。

圖14.png
- 點(diǎn)擊進(jìn)入Classpath選項(xiàng)卡,選中User Entries,然后點(diǎn)擊右側(cè)的Advanced按鈕,會(huì)彈出一個(gè)小框,選擇Add Folders,單擊OK。
選擇 openfire\src\i18n點(diǎn)OK 按鈕將這個(gè)文件夾加入到Classpath選項(xiàng)卡中
選擇 openfire\src\resources 目錄也加到 Classpath選項(xiàng)卡中
點(diǎn)擊Apply應(yīng)用。

圖15.png

圖16.png
- 點(diǎn)擊進(jìn)入Common選項(xiàng)卡中,勾選Run復(fù)選框,點(diǎn)擊Apply應(yīng)用。

圖17.png
- 點(diǎn)擊Run運(yùn)行。 程序正常運(yùn)行結(jié)果如下。

圖18.png
- 在瀏覽器中輸入http://127.0.0.1:9090運(yùn)行后顯示結(jié)果如下

圖19.png
- 這是由文件路徑所導(dǎo)致的,解決方法: 點(diǎn)擊進(jìn)入Classpath選項(xiàng)卡,選中User Entries,然后點(diǎn)擊右側(cè)的Advanced按鈕,會(huì)彈出一個(gè)小框,選擇Add Folders,單擊OK。
選擇 openfire\src\resources\jar 目錄也加到 Classpath選項(xiàng)卡中
點(diǎn)擊Apply應(yīng)用。

圖20.png