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程序调试自己的代码!

猜你喜欢

转载自blog.csdn.net/dragonrxl/article/details/8197290