Mac下即时通讯openfire在本地搭建(Eclipse)

1.首先下载Eclipse以及openfire源码 我下载的版本是openfire_src_4_1_5.tar.gz    

2.打开解压缩后的openfire源码文件夹,依次进入build-->eclipse  可以看到eclipse中有两个文件classpath 和project 和settings文件夹,将三个复制并粘贴到源码目录下和build目录平级,对三个文件进行重命名,classpath--> .classpath 要注意的是 ,mac下 以‘.’ 开头的文件被认为是系统文件,不能直接更改,所以这三个文件要用到shell命令行来更改,分别在前面加上一个'.'  

3.打开Eclipse  File -->Import-->general-->Existing Project into workspace 选择文件夹导入已经修改好的openfire源码。在学习的时候,网上找了很多的教程,都说在导入之后,项目名字会出现红色的✘   可能是因为我的版本相对最高,中间缺少的jar被补全了。

4.ANT编译项目

Eclipse已经集成了Ant,所以我们只需要在 /openfire_src/build/build.xml 文件右击,选择Run As –> Ant Build 即可完成编译,编程成功后,会在/openfire_src/的跟目录下生成两个新的文件夹:target 和 work 。

****************************************************************************************************不知道为什么,在我执行完ant build之后,eclipse中只出现了work目录,target目录没有出现,后来在shell中ls的时候发现,target存在但是就是不在eclipse中显示,查了好久没有结果直接放弃向后面进行。不知道为什么最后成功了,如果有谁知道,请告知。*****************************************************************************************************

5、运行Openfire项目

①、在Build Path配置中把  /openfire_src/src/i18n 、/openfire_src/src/resources/jar 、/openfire_src/build/lib/dist 文件夹添加到 Source 中,如图:

Mac下即时通讯openfire在本地搭建(Eclipse)

②配置启动参数

选择Run –> Run Configurations… 左边的Java Application,单击右键,选择 New:

Mac下即时通讯openfire在本地搭建(Eclipse)

把默认name:New_configuration 修改成:ServerStarter。

选中Main选项卡,点击Browse按钮选择 openfire_src 项目;单击Search 按钮输入:ServerStarter 自动过滤后选择:ServerStarter – org.jivesoftware.openfire.starter:

Mac下即时通讯openfire在本地搭建(Eclipse)

选中Arguments选项卡,在VM arguments中填入:

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

注意:项目路径 ${workspace_loc:openfire_src}

选中Common选项卡,将Debug和Run打钩(方便之后快速启动),然后点击apply,再点击run:

Mac下即时通讯openfire在本地搭建(Eclipse)

③运行后控制台日志如下:

Mac下即时通讯openfire在本地搭建(Eclipse)

④浏览器中输入地址: http://127.0.0.1:9090 回车:

Mac下即时通讯openfire在本地搭建(Eclipse)






如果在启动的时候出现错误。

1.The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletException. Fix the build path then try building this project


---------出现这个错误的原因是jre没有配置好,右键项目名 build path配置好自己对应的版本


2.

 No custom config here 

出现这个错误的原因是

Mac下即时通讯openfire在本地搭建(Eclipse)


这个类中的路径需要配置成自己本机的对应路径 

找到

 openfireHome = verifyHome("..", jiveConfigName).getCanonicalFile();   

其中的.. 改成ant build之后target下openfire的路径,即打包之后的包的路径   如 我的是

/Users/ssf/Documents/EclipseWorkspace/openfire_src/target/openfire


修改之后,重新运行就可以了,在地址栏输入localhost:9090  出现上面介绍的画面,就成功了