由于工作需要,这几天在研究openfire的插件开发,整的头都大了,配置环境、部署源码...由于网上的资料五花八门,几乎每种都试过,好多是走不通的,所以在这里记录一下我部署openfire源码的流程,分享给大家,也方便以后时间长了如果忘记可以参考,这可是我的血泪史啊...
首先,介绍几个概念:
XMPP:就是一个发送接收处理消息的协议,通过XML机制实现
IM:即时通信软件,如QQ、MSN等
Spark Smack 和 Openfire:
这些都是开源的,三个合起来就是一个完整的XMPP IM实现,包括服务器端——Openfire,客户端——Spark,XMPP 传输协议的实现——Smack(XMPP是一个协议,协议是
需要实现的,Smack起到的就是这样的一个作用,就是一套API,可扩展)。三者都是基于Java 语言的实现。
我是做android的,它用到的XMPP协议是asmack(其实和smack差不多的),现在已经实现android客户端向openfire注册、登录、添加好友、获取好友状态、一对一聊天
、建群等功能,其实不难,都是直接调用API就行了。之后就开始研究openfire的插件开发了,开发of插件第一句是部署源码,本文的重点就在这里。
第一步:去openfire官网下载of源码,openfire_src
第二步:下载完成解压到工作空间文件夹内
第三步:在eclipse中新建一个工程,命名:openfire_src,这样就相当于把刚才下载的源码自动导入这个新建的项目里了
第四步:此时,项目肯定会显示红叉,右击openfire_src工程-build path-Configure Build path...-Libraries-将openfire_src\build\lib下的所有jar包都导入
第五步:导入jar包之后,如果项目还有红叉,说明还缺少三个jar包:coherence.jar、coherence-work.jar、tangosol.jar,搞到这3个包按上面的方法导入,然后按
eclipse的提示处理后,就可以了
第六步:接下来是配置openfire运行时的参数,如下:
Run -- Run configuration
选择Java Application 右键 新建一个Java application 重新命名为openfire
选择刚才建的项目openfire
Main class:(search) org.jivesoftware.openfire.starter.ServerStarter
单击 Arguments 选框
在 VM-Arguments 键入
-DopenfireHome="${workspace_loc:openfire}/target/openfire"
此处实际上是告诉 openfire ,openfireHome 在什么地方,用于eclipse执行
java命令时传递的参数,openfire程序可以通过System.getProperty("openfireHome")得到 openfire的本地位置。
点击classpath 选项
User entries --->Advanced-->Add Folder---> OK
添加以下三目录
openfire::src::i18n
openfire::src::resources::jar
openfire::build::lib::dist
点击Common tab
勾选 Debug和Run复选框
设置虚拟机参数
点击JRE tab
installed JRES -->选中使用的JRE --->Edit -->Default VM Arguments
-Xms256m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
如果是默认的大小很可能报
java.lang.OutOfMemoryError: PermGen space异常。
第七步:利用ant编译openfire
1. eclipse中点击Window-->Show View-->Ant
2. 在Ant 页面点右键,选择 Add Buildfiles...
3. 展开openfire/build文件夹,选择build.xml, 点 OK.
4. 在Ant页面, 展开Openfire XMPP Server,双击 openfire ant 任务,会在控件台上输出运行成功的日志。
至此,openfire源码部署、运行完毕!
============================= 华丽的分割线 =============================
以下是官方指导的部署步骤,来自http://community.igniterealtime.org/docs/DOC-1020
This guide assumes that you are installing everything from scratch. If you've done some parts of them, this guide may still be useful. I compiled this guide to the best of my knowledge. I apologize if it doesn't work for you.
Notes:
-
Install JDK
Install Eclipse 3.3
-
Download Eclipse 3.3 from www.eclipse.org. I use Eclipse IDE for Java EE Developers. You should
at least useEclipse IDE for Java Developers.
-
Extract the downloaded zip file into C:/Program Files/Eclipse.
-
Open C:/Program Files/Eclipse folder.
-
Right click and drag eclipse.exe on to your desktop (or Windows taskbar) to create a shortcut
icon.
-
Right click the shortcut icon and choose Properties. The Eclipse
Properties window will show.
-
The Target textbox should read something like this "C:\Program
Files\Eclipse\eclipse.exe" -vm "C:\Program Files\Java\jdk1.6.0\bin\javaw" depending on the JDK that you use and where you installed it.
-
Close the Eclipse Properties window.
Install Subversive Plugin
-
Double-click the shortcut icon to start Eclipse.
-
Select/enter your preferred workspace and click OK to open Eclipse main IDE window.
-
Click on the Workbench icon to close the welcome screen.
-
Click Help::Software Updates::Find and Install... menu.
-
Click on Search for new features to install and click Next.
-
Click on New Remote Site... button.
-
Enter Subversive in the Name box
and http://www.polarion.org/projects/subversive/download/1.1/update-site in
the URL box (Check the latest URL from http://www.eclipse.org/subversive website),
then click OK.
-
Click Finish to install Subversive. Eclipse will search for the update site and show the result
in a next window where you will select the features to install. I choose everything under Subversive
SVN Team Provider Plugin andSubversive Client Libraries.
-
Click Next to continue and so on until the installation ends. You normally want to restart Eclipse
when the installation ends.
Check Out Openfire SVN
-
Click Windows::Open Perspective::Other... menu.
-
Click on SVN Repository Exploring on the Open
Perspective window and click OK.
-
Right-click on SVN Repositories screen and choose New::Repository
Location...
-
On New Repository Location enter http://svn.igniterealtime.org/svn/repos in
the URL box and click Finish. You'll see the URL location in the SVN
Repositories screen.
-
Expand the URL location.
-
Expand the openfire tree.
-
Right-click on trunk and choose Check
Out. Make yourself some Cafe-Latte while waiting for the checkout to complete.
Create Openfire Project
-
Click Window::Open Perspective::Java menu.
-
In the Project Explorer screen, if there is an openfire project,
delete it. This project was created during the Openfire check out process. Yes you read it correctly, DELETE the project!!! Otherwise you'll have to setup your Openfire development environment manually. On the Confirm
Project Delete choose Do not delete contents, then click Yes.
-
Click File::New::Project... Notice the ellipses!!!
-
Select Java::Java Project and click Next.
-
On the New Java Project window choose Create
project from existing source and browse to where openfirefolder is located under your
workspace.
-
In the Project name box enter exactly as openfire.
Otherwise, the Next and Finish button
remain disabled. Click onNext. Eclipse will read the directory structure to setup the environment
automatically (almost) for you and you can see what it does on the next screen. Then click on Finish.
-
If the Open Associated Perspective windows opens, click Yes.
Build Openfire
-
Click Window::Show View::Ant menu.
-
Right-click the Ant screen and choose Add
Buildfiles...
-
Expand the openfire::build folder and select build.xml,
then click OK.
-
On the Ant screen, expand the Openfire
XMPP Server and double-click on openfire ant task. The build may fail because you're checking
out the daily updates of Openfire sources, which may contain bugs. If so, wait for another day and hope that the developers discover and fix the bug; or you might dare to fix it yourself. During this first time setup, a successful build is necessary before
you can proceed with the remaining tasks below.
Create Project Builder
-
Click Run::Open Run Dialog... or Run::Open
Debug Dialog... menu. A Run window shows.
-
Select Java Application and click on the New button.
-
On the Main tab of the Run window,
change the New_configuration name to Openfire or
anything you like.
-
Click on Project::Browse button and select openfire and
click OK.
-
Click on Main class::Search button and select ServerStarter
- org.jivesoftware.openfire.starter and click OK.
-
I'd suggest that you select Stop in main check box so that you could later verify that debugging
works.
-
Click on the Arguments tab.
-
Enter -DopenfireHome="${workspace_loc:openfire}/target/openfire" in the VM
arguments box.
-
Click on Classpath tab.
-
Select User Entries so that the Advanced... button
will be enabled.
-
Click on the Advanced... button.
-
On the Advanced Options window select Add
Folders and click OK.
-
On the Folder Selection window select openfire::src::i18n folder
and click OK.
-
Click on the Advanced... and Add
Folders buttons once again to include openfire::src::resources::jar folder.
-
Click on the Advanced... and Add
Folders buttons once again to include openfire::build::lib::dist folder.
-
Click on Common tab.
-
Select the Debug and Run check
box.
-
Click on Apply button.
-
Click on Close button.
Run/Debug
-
The setting is now complete for Openfire.
-
You may test running and debugging by clicking on Run::Run History::Openfire and Run::Debug
History::Openfirerespectively. If you choose the later and if you follow this instruction closely, execution will stop on the main method in ServerStarter.java.
Plugin Setup
Related Documents