openfire 源碼 部署

  1. 1.複製src\java下所有東西;   
  2. 2.openfire\src\i18n, 點OK按鈕將這個文件夾加入到Classpath選項卡中;   
  3. 3.同樣的方式把openfire\src\resources目錄下的jar文件夾也加到Classpath選項卡中。   
  4. 4.openfire的起始類爲org.jivesoftware.openfire.starter.ServerStarter.java,但是直接運行此類卻有問題,因爲此類是針對Openfire安裝包而設計的,此類的功能是將所用到的JAR文件解壓並將class文件加載到虛擬機中,而我們要用的卻是源代碼中我們自己編譯好的class文件。所以,我們需要一個新的啓動類。   
  5. 一個簡單的實現方法就是把src/java下的東西複製到我創建的java project下的src裏了,並修改org.jivesoftware.openfire.starter包中ServerStarter.java類的源代碼,具體如下(當然最好是與ServerStarter.java中的方法一樣,用自定義的ClassLoader來將XMPPServer.class加載到虛擬機中)   
  6. package org.jivesoftware.openfire.starter;   
  7. import org.jivesoftware.openfire.XMPPServer;   
  8. public class StandaloneStarter {   
  9.   
  10. public static void main(String[] args) {   
  11.   
  12. XMPPServer server = new XMPPServer();   
  13.   
  14. }   
  15. }   
  16. 這樣程序就可以跑起來了,最後的問題就是配置文件路徑的問題。   
  17. 5.配置文件路徑   
  18. 如果文件路徑配置不正確(即Openfire的Home沒有設定或者設置不正確),就可能在運行時出現如下所示的問題:   
  19. Could not locate home   
  20. java.io.FileNotFoundException......   
  21.   
  22. ERROR 12114 [Jive-ERR] ():    
  23. java.io.FileNotFoundException: XML properties file does not exist: openfire.xml........   
  24. 在XMPPServer類中有一個locateOpenfire方法,這個方法就是設置openfireHome屬性。   
  25. 1部分的代碼如下:   
  26. String jiveConfigName = "conf" + File.separator + "openfire.xml";   
  27. // First, try to load it openfireHome as a system property.   
  28. if (openfireHome == null) {   
  29. String homeProperty = System.getProperty("openfireHome");   
  30. try {   
  31. if (homeProperty != null) {   
  32. openfireHome = verifyHome(homeProperty, jiveConfigName);   
  33. }   
  34. }   
  35. catch (FileNotFoundException fe) {   
  36. // Ignore.   
  37. }   
  38. }   
  39. 是在環境變量設置了Openfire的Home的情況下尋找openfire.xml文件   
  40.   
  41. 你可以更改第二部分的代碼讓Openfire找到Home:   
  42. // If we still don't have home, let's assume this is standalone   
  43. // and just look for home in a standard sub-dir location and verify   
  44. // by looking for the config file   
  45. if (openfireHome == null) {   
  46. try {   
  47. //修改的是下面的代碼,將".."替換爲其他路徑了   
  48. openfireHome=verifyHome("C:\\Program Files\\Openfire", jiveConfigName).getCanonicalFile();   
  49. }   
  50. catch (FileNotFoundException fe) {   
  51. // Ignore.   
  52. }   
  53. catch (IOException ie) {   
  54. // Ignore.   
  55. }   
  56. }   
  57. 這部分默認是找當前文件路徑,你可以修改它爲你安裝openfire的路徑,這樣問題就可以解決了。   
  58. 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   
  59. 修改org.jivesoftware.openfire.starter.ServerStarter中的如下兩個field,   
  60. private static final String DEFAULT_LIB_DIR = "../lib";   
  61. private static final String DEFAULT_ADMIN_LIB_DIR = "../plugins/admin/webapp/WEB-INF/lib";   
  62. 改成:   
  63. private static final String DIR_PREFIX = "$openfire_home";   
  64. // to be your own openfire_home   
  65. private static final String DEFAULT_LIB_DIR = DIR_PREFIX + "lib";   
  66. private static final String DEFAULT_ADMIN_LIB_DIR = DIR_PREFIX + "plugins/admin/webapp/WEB-INF/lib";   
  67. 現在還不知道這裏爲什麼要這樣做????? 

最後總結:調試的時候需要用自己寫的插件代碼,然後運行安裝好的openfire程序調試自己的代碼!

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