由于工作需要,这几天在研究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
Openfire SVN + Eclipse 3.3 + Subversive Installation Guide
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:
-
This guide assumes that you want the latest updates of the source i.e. from the project'strunkdirectory. If you only want the released/stable version, checkout the desired release from under thetagsdirectory.
-
Install JDK
-
Download JDK and install them. The least version should be 1.5. I use 1.6. Sorry, no instruction for this.
Install Eclipse 3.3
-
Download Eclipse 3.3 from www.eclipse.org. I useEclipse IDE for Java EE Developers. You should at least useEclipse IDE for Java Developers.
-
Extract the downloaded zip file intoC:/Program Files/Eclipse.
-
OpenC:/Program Files/Eclipsefolder.
-
Right click and drageclipse.exeon to your desktop (or Windows taskbar) to create a shortcut icon.
-
Right click the shortcut icon and chooseProperties. TheEclipse Propertieswindow will show.
-
TheTargettextbox 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 theEclipse Propertieswindow.
Install Subversive Plugin
-
Double-click the shortcut icon to start Eclipse.
-
Select/enter your preferred workspace and clickOKto open Eclipse main IDE window.
-
Click on theWorkbenchicon to close the welcome screen.
-
ClickHelp::Software Updates::Find and Install...menu.
-
Click onSearch for new features to installand clickNext.
-
Click onNew Remote Site...button.
-
EnterSubversivein theNamebox andhttp://www.polarion.org/projects/subversive/download/1.1/update-sitein the URL box (Check the latest URL fromhttp://www.eclipse.org/subversivewebsite), then clickOK.
-
ClickFinishto 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 underSubversive SVN Team Provider PluginandSubversive Client Libraries.
-
ClickNextto continue and so on until the installation ends. You normally want to restart Eclipse when the installation ends.
Check Out Openfire SVN
-
ClickWindows::Open Perspective::Other...menu.
-
Click onSVN Repository Exploringon theOpen Perspectivewindow and clickOK.
-
Right-click onSVN Repositoriesscreen and chooseNew::Repository Location...
-
OnNew Repository Locationenterhttp://svn.igniterealtime.org/svn/reposin the URL box and clickFinish. You'll see the URL location in theSVN Repositoriesscreen.
-
Expand the URL location.
-
Expand theopenfiretree.
-
Right-click ontrunkand chooseCheck Out. Make yourself some Cafe-Latte while waiting for the checkout to complete.
Create Openfire Project
-
ClickWindow::Open Perspective::Javamenu.
-
In theProject Explorerscreen, if there is anopenfireproject, 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 theConfirm Project DeletechooseDo not delete contents, then clickYes.
-
ClickFile::New::Project...Notice the ellipses!!!
-
SelectJava::Java Projectand clickNext.
-
On theNew Java Projectwindow chooseCreate project from existing sourceand browse to whereopenfirefolder is located under your workspace.
-
In theProjectnamebox enter exactly asopenfire. Otherwise, theNextandFinishbutton 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 onFinish.
-
If theOpen Associated Perspectivewindows opens, click Yes.
Build Openfire
-
ClickWindow::Show View::Antmenu.
-
Right-click theAntscreen and chooseAdd Buildfiles...
-
Expand theopenfire::buildfolder and selectbuild.xml, then clickOK.
-
On theAntscreen, expand theOpenfire XMPP Serverand double-click onopenfireant 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
-
ClickRun::Open Run Dialog...orRun::Open Debug Dialog...menu. ARunwindow shows.
-
SelectJava Applicationand click on theNewbutton.
-
On theMaintab of theRunwindow, change theNew_configurationname toOpenfireor anything you like.
-
Click onProject::Browsebutton and selectopenfireand clickOK.
-
Click onMain class::Searchbutton and selectServerStarter - org.jivesoftware.openfire.starterand clickOK.
-
I'd suggest that you selectStop in maincheck box so that you could later verify that debugging works.
-
Click on theArgumentstab.
-
Enter-DopenfireHome="${workspace_loc:openfire}/target/openfire"in theVM argumentsbox.
-
Click onClasspathtab.
-
SelectUser Entriesso that theAdvanced...button will be enabled.
-
Click on theAdvanced...button.
-
On theAdvanced Optionswindow selectAdd Foldersand clickOK.
-
On theFolder Selectionwindow selectopenfire::src::i18nfolder and clickOK.
-
Click on theAdvanced...andAdd Foldersbuttons once again to includeopenfire::src::resources::jarfolder.
- Click on theAdvanced...andAdd Foldersbuttons once again to includeopenfire::build::lib::distfolder.
-
Click onCommontab.
-
Select theDebugandRuncheck box.
-
Click onApplybutton.
-
Click onClosebutton.
Run/Debug
-
The setting is now complete for Openfire.
-
You may test running and debugging by clicking onRun::Run History::OpenfireandRun::Debug History::Openfirerespectively. If you choose the later and if you follow this instruction closely, execution will stop on the main method inServerStarter.java.
Plugin Setup
-
Please refer toOpenfire Plugins Setup Guide For Eclipse
Related Documents
-
Openfire .tar.gz + Eclipse 3.1 Installation Guide- Installation guide for those who prefer to download the source code in tarball format.
-
Spark SVN + Eclipse 3.3 + Subversive Installation Guide- Installation guide for Spark.