`
zhonglunshun
  • 浏览: 134800 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

openfire在eclipse中的环境搭建和编译详解

阅读更多

 因为项目需要去研究了openfire,刚开始按照视频教程开始弄得,不知为何在eclipse里面怎么也build不起来,终于弄好了,和大家交流下经验。

 

材料(准备工作)

 

1.Openfire源码,下载我就不说了,百度即可。下载过来后解压。

2.Install4j,这个很重要,之前就是因为这个没有配置好导致失败的。因为openfire的编译是要依赖这个东西的,我们把这个东西下载过来,解压到其默认的安装路径C:/Program Files/install4j下。(我是这么做的,不这么放没试过)。

 

 

安装

1)打开eclipse->File->New Java Project

2.勾掉"Use default location",然后点击右边的"Browse...",openfire_src_3_7_1\openfire_src目录

3.点击Finish. 到此工程已经被正常导入。

4.修改build.xml 文件找到文件

 

<condition property="java.not.ok" value="true">
  <not>
    <or>
      <contains string="${ant.java.version}" substring="1.5"/>
      <contains string="${ant.java.version}" substring="1.6"/>
    </or>
  </not>
</condition>
更改如下:
<condition property="java.not.ok" value="true">
  <not>
    <or>
      <contains string="${ant.java.version}" substring="1.5"/>
      <contains string="${ant.java.version}" substring="1.6"/>
      <contains string="${ant.java.version}" substring="1.7"/>
    </or>
  </not>
</condition>

 

 

如果你的jdk1.8那就在后面添加<contains string="${ant.java.version}" substring="1.8"/>

5.接下来就是导包,在Package Explorer视图中,右击openfire工程,选择Properties,在弹出的对话框中选择Libraries->Add JARs..,把openfire_src_3_5_1/build/lib目录下的*.jar类库全部添加进来;选择Source标签页,Add Folder..,选中src/java目录前的复选框,点击OK,点击OK按钮。

 

编译阶段

1)在eclipse中点击Window->Show View->Ant,打开Ant窗口;

2)在Ant 视图中,单击右键,在弹出的快捷菜单中选择Add Buildfiles..

3)在弹出的对话框中,展开openfire/build文件夹,选择build目录下的build.xml,点击OK

4)在Ant视图中, 展开Openfire XMPP Server,双击 openfiredefault)编译工程

5)如果在Console视图中显示“BUILD SUCCESSFUL”就表示编译成功。

 

创建项目Builder

1)在eclipse的菜单栏中,选择Run->Open Run Dialog...,在弹出的对话框左侧的树形结构中选择Java Application,单击右键,选择New创建启动配置。

2) 在Run窗口的Main选项卡中, 修改Name文本框中的值,改成包含要启动的类的工程名openfire

3)在Run窗口的Main选项卡中,点Browse按钮,选择openfire

4)在Run窗口的Main选项卡中,点Search按钮,选择Main class

org.jivesoftware.openfire.starter.ServerStarter,单击Apply按钮。(这是openfire的启动类)

5)点击进入Arguments选项卡,在VM arguments文本框中输入

-DopenfireHome="${workspace_loc:openfire}/target/openfire"

单击Apply按钮。这个是用于eclipse执行java命令时传递的参数,这样openfire程序可以通过System.getProperty(openfireHome)得到openfire的本地位置。

6)点击进入Classpath选项卡,选中User Entries,这样Advanced...就处于可用状态;点击Advanced...按钮,在Advanced Options页面,选择Add Folders, 单击OK。(默认情况下,已经将工程openfire添加到了这里,而不需要进行该项操作,如果有多个工程的时候才需要执行该项操作。)

选择openfire/src/i18n, OK按钮将这个文件夹加入到Classpath选项卡中;同样的方式把openfire/src/resources目录下的jar文件夹也加到Classpath选项卡中。

11点击进入Common选项卡中,勾选Run复选框。

点击Apply应用。

 

在进行这些配置之后,就算是基本完工了。

可以直接点击配置框最下方的Run按钮,或者单击菜单栏Run->Run开始跑程序。

 

log4j:WARN No appenders could be found for logger (org.jivesoftware.util.Log).
log4j:WARN Please initialize the log4j system properly.
Openfire 3.7.0 [Jun 29, 2011 1:51:19 PM]
Admin console listening at <a href="http://127.0.0.1:9090">http://127.0.0.1:9090</a>

 

启动成功,那么在浏览器中输入http://127.0.0.1:9090测试一下吧!

 

错误处理

 

在配置完成后,有些同学启动项目并不会正常启动,而是会出现一些其他错误。

 

log4j:WARN No appenders could be found for logger (org.jivesoftware.util.Log).
log4j:WARN Please initialize the log4j system properly.
Could not locate home
java.io.FileNotFoundException
	at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:874)
	at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:347)
	at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:468)
	at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:212)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:113)
	at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58)
启动服务器时出错。请检查日志文件以获取更多信息。

 

 

这种情况是由于源码中配置的路径错误引起的,请打开文件org.jivesoftware.openfire.XMPPServer

 

我们看到里面有这一行

 

 // 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("..", jiveConfigName).getCanonicalFile();
            }
            catch (FileNotFoundException fe) {
                // Ignore.
            }
            catch (IOException ie) {
                // Ignore.
            }
        }

 

 

请看verifyHome方法的第一个参数,这里配置的就是相对的路径“..”而我们重新编译的时候,配置到的路径不是这里,那么就要根据你配置的路径来修改前面的地址。

 

我的是这样:

 

openfireHome = verifyHome("D:\\openfire_src\\openfire_src\\target\\openfire", jiveConfigName).getCanonicalFile();

 

我的配置在:openfire_src\\openfire_src\\target\\openfire文件夹下。

 

 

 

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics