第十章 Openfire插件开发规范
在源码导入之后我们可以定制一些自己的插件系统
1.参考自带插件的目录结构
大致目录结构,其中hangelog.html、plugin.xml、readme.html这三个文件分别是你的插件修改日志文件,插件文件和自述文件。然后还有LOGO,随便拷几个就可以。最重要的是plugin.xml文件。我们稍后在说
2.建立我们自己的插件
1.新建插件目录
其中lib明显是放置jar包用.
然后src目录:
src
--java
--web
2.作为源码包 然后java -buildpath 作为源码包使用 use folder source
然后我们发现包到了这里
3.编写插件。
新建包,以及类
package com.helloworld;
import java.io.File;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
public class HelloWorldPlugin implements Plugin{
private XMPPServer server;
public HelloWorldPlugin() {
}
@Override
public void initializePlugin(PluginManager manager, File pluginDirectory) {
// TODO Auto-generated method stub
server = XMPPServer.getInstance();
System.out.println("HelloWorldPlugin----start");
System.out.println(server.getServerInfo());
}
@Override
public void destroyPlugin() {
System.out.println("HelloWorldPlugin----destroy");
}
}
其中的插件类必须要继承Plugin类,我们编写的这个类就是在启动和停止时候输出。
4.编写plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>com.helloworld.HelloWorldPlugin</class>
<name>helloWorld</name>
<description>First Openfire Custom Plugin.</description>
<author>xiaoqiang</author>
<version>1.0.0</version>
<date>2016-07-04</date>
<minServerVersion>4.0.0</minServerVersion>
<adminconsole>
</adminconsole>
</plugin>
大致内容: class:我们插件类所在的位置 name:名字 description:描述 author:作者 version:版本 date:日期 minServerVersion:最低要求版本
adminconsole:控制台界面
其中控制台界面我们是不需要的。
5.编译插件
在我们的build目录里面
里面build.properties.templete 是模板文件,我们修改这个模板文件。
#
# $RCSfile$
# $Revision$
# $Date$
#
#
# Directory where the jar files will be deployed (see the deployjar task)
#
deploy.jar.dir=
plugin=helloWorld
#
# Directory where plugin development is done. This is assumed to be the
# root directory:
#
# /home/joeuser/java/myplugins/ <- Point to this directory
# |- fooplugin/
# |- barplugin/
#
plugin.dev.dir=
#
# Path to your Install4j installation. Typically this is c:\Program Files\install4j
# This property is set by default in the build.xml file as c:\Program Files\install4j so
# if you used the standard location you won't need to edit the property below.
#
# installer.install4j.home=
#
# Path to a bundled JRE you wish to use with the installer.rpm ant target
#
jre.bundle.location=
将plugin=helloWorld 添加进去
然后使用ant 编译
build.xml-->run as ...
选择插件然后run.
顺利的话就会编译成功。然后我们会发现在。
在work里面就会多出一个我们的插件,那么重新启动openfire那么我们就会发现
我们的插件起作用了。