废话不说,直接进入主题。(如何部署、运行OF源码,请参照别的文章)。
1.部署成功后的openfire源码如下图,
![](https://img-blog.csdn.net/20130807103415781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2.转到Navigator视图下,
![](https://img-blog.csdn.net/20130807103427781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
3.看of的插件目录结构,以后自己生成的插件目录结构也应该是这种结构的,
![](https://img-blog.csdn.net/20130807103553828?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
4.再回到Packager Explorer视图下,右键->new->source foulder,创建一个源代码目录,
![](https://img-blog.csdn.net/20130807103428031?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
5.在源代码目录下创建package,
![](https://img-blog.csdn.net/20130807103443437?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
6.创建插件类实现Plugin接口,在initializePlugin\destroyPlugin方法中,分别负责初始化插件和销毁插件。
代码如下:
- package com.bis.plugin.messageplugin;
-
- import java.io.File;
-
- import org.jivesoftware.openfire.container.Plugin;
- import org.jivesoftware.openfire.container.PluginManager;
-
- public class MessagePlugIn implements Plugin {
- private static PluginManager pluginManager;
- @Override
- public void initializePlugin(PluginManager manager, File pluginDirectory) {
- pluginManager = manager;
- System.out.println("加载插件成功!");
- }
-
- @Override
- public void destroyPlugin() {
- System.out.println("销毁插件成功!");
- }
-
- }
7.再回到Navigator视图下,
![](https://img-blog.csdn.net/20130807103427781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
8.找到plugins/messageplugin,在从别的插件包下复制一个plugin.xml到messageplugin文件夹下,
![](https://img-blog.csdn.net/20130807104321406?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
9.plugin.xml内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <plugin>
-
- <class>com.bis.plugin.messageplugin.MessagePlugIn</class>
-
- <name>MessagePlugIn</name>
-
- <description>this is a MessagePlugIn</description>
-
- <author>Ma Jian</author>
-
- <version>1.0.0</version>
-
- <date>08/7/2013</date>
-
- <minServerVersion>3.7.1</minServerVersion>
- </plugin>
10.从Window->show view->Ant,打开Ant视图,在Ant视图中,右键添加ant builder,
![](https://img-blog.csdn.net/20130807104846937?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
11.在Ant视图中,展开Ant的节点,然后找到plugins,在pluins上右键Run As Ant Builder,
![](https://img-blog.csdn.net/20130807104902796?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuXzE5ODc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
至此,插件开发编译完成,到openfire_src\target\openfire\plugins下,找到生成的插件jar包,这就是生成的插件包,可以放在openfire服务器的plugins目录下,启动后就可以运行了。