openfire导入eclipse之二Could not locate home 编译运行

按照之前的导入方法成功导入后,报错消失了,这时候用eclipse编译openfire。

(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

 

如果出现Could not locate home 异常。报错的代码在XMPPServer.java中:

private void locateOpenfire() throws FileNotFoundException{
        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.
            }
        }

        // 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.
            }
        }
         
        .....

}

 这段代码的意思是根据系统配置来寻找Openfire的启始目录。解决方式,就是用ant先编 译一遍,然后就可以了。

顺便说一下,在windows下安装JDK后,直接ant编译,如果不手动设置java环境变量会报错:

Unable to find a javac compiler,

 遇到这种情况时直接将C:\Program Files\Java\jdk1.6.0_17\lib中的tools.lib拷贝到C:\Program Files\Java\jre6\lib中即可。

 然后再用eclipse编译openfire就可以了。

 

在window下编译运行后,登录openfire,如果报错:

HTTP ERROR 500

Problem accessing /setup/index.jsp. Reason:

    Server Error
解决方式:把src/resources/jar/admin-sidebar.xml这个文件拷入项目下的bin目录

你可能感兴趣的:(Openfire,编译,eclipse,windows,开源服务器)