- 1.複製src\java下所有東西;
- 2.openfire\src\i18n, 點OK按鈕將這個文件夾加入到Classpath選項卡中;
- 3.同樣的方式把openfire\src\resources目錄下的jar文件夾也加到Classpath選項卡中。
- 4.openfire的起始類爲org.jivesoftware.openfire.starter.ServerStarter.java,但是直接運行此類卻有問題,因爲此類是針對Openfire安裝包而設計的,此類的功能是將所用到的JAR文件解壓並將class文件加載到虛擬機中,而我們要用的卻是源代碼中我們自己編譯好的class文件。所以,我們需要一個新的啓動類。
- 一個簡單的實現方法就是把src/java下的東西複製到我創建的java project下的src裏了,並修改org.jivesoftware.openfire.starter包中ServerStarter.java類的源代碼,具體如下(當然最好是與ServerStarter.java中的方法一樣,用自定義的ClassLoader來將XMPPServer.class加載到虛擬機中)
- package org.jivesoftware.openfire.starter;
- import org.jivesoftware.openfire.XMPPServer;
- public class StandaloneStarter {
- public static void main(String[] args) {
- XMPPServer server = new XMPPServer();
- }
- }
- 這樣程序就可以跑起來了,最後的問題就是配置文件路徑的問題。
- 5.配置文件路徑
- 如果文件路徑配置不正確(即Openfire的Home沒有設定或者設置不正確),就可能在運行時出現如下所示的問題:
- Could not locate home
- java.io.FileNotFoundException......
- ERROR 12114 [Jive-ERR] ():
- java.io.FileNotFoundException: XML properties file does not exist: openfire.xml........
- 在XMPPServer類中有一個locateOpenfire方法,這個方法就是設置openfireHome屬性。
- 第1部分的代碼如下:
- String jiveConfigName = "conf" + File.separator + "openfire.xml";
- // First, try to load it openfireHome as a system property.
- if (openfireHome == null) {
- String homeProperty = System.getProperty("openfireHome");
- try {
- if (homeProperty != null) {
- openfireHome = verifyHome(homeProperty, jiveConfigName);
- }
- }
- catch (FileNotFoundException fe) {
- // Ignore.
- }
- }
- 是在環境變量設置了Openfire的Home的情況下尋找openfire.xml文件
- 你可以更改第二部分的代碼讓Openfire找到Home:
- // If we still don't have home, let's assume this is standalone
- // and just look for home in a standard sub-dir location and verify
- // by looking for the config file
- if (openfireHome == null) {
- try {
- //修改的是下面的代碼,將".."替換爲其他路徑了
- openfireHome=verifyHome("C:\\Program Files\\Openfire", jiveConfigName).getCanonicalFile();
- }
- catch (FileNotFoundException fe) {
- // Ignore.
- }
- catch (IOException ie) {
- // Ignore.
- }
- }
- 這部分默認是找當前文件路徑,你可以修改它爲你安裝openfire的路徑,這樣問題就可以解決了。
- 6.將新建的工程目錄下src/web/WEB-INF/classes/openfire_init.xml導入到eclipse的查詢路徑裏,如將src/web/WEB-INF/classes目錄作爲eclipse的源目錄,這樣openfire_init.xml自動copy到$openfire_home/classses下面,將openfire_init.xml中的openfireHome設置爲$openfire_home
- 修改org.jivesoftware.openfire.starter.ServerStarter中的如下兩個field,
- private static final String DEFAULT_LIB_DIR = "../lib";
- private static final String DEFAULT_ADMIN_LIB_DIR = "../plugins/admin/webapp/WEB-INF/lib";
- 改成:
- private static final String DIR_PREFIX = "$openfire_home";
- // to be your own openfire_home
- private static final String DEFAULT_LIB_DIR = DIR_PREFIX + "lib";
- private static final String DEFAULT_ADMIN_LIB_DIR = DIR_PREFIX + "plugins/admin/webapp/WEB-INF/lib";
- 現在還不知道這裏爲什麼要這樣做?????
最後總結:調試的時候需要用自己寫的插件代碼,然後運行安裝好的openfire程序調試自己的代碼!