Openfire代码阅读之二--插件(系列一)

本文介绍了Openfire插件的概念及开发流程。Openfire通过插件机制允许开发者在不改动核心代码的情况下添加新功能。文章详细阐述了插件的目录结构、plugin.xml配置文件的作用及其各个字段的含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Openfire代码阅读之二--插件

系列一

whuige(whuige@gmail.com)

 

插件的概念


插件是一种遵循一定规范的应用程序接口编写出来的程序。在Openfire项目中,采用了插件的机制,它促使你可以在不改变核心代码的基础上,增加多种你需要的功能;同时,它可以减少你部署和测试的工作量,对于后期的程序维护也有很大的好处:当你需要对某一个插件进行升级时, 只需要动态的unload这个插件,然后patch,上传到服务器中即可。你甚至可以不需要停止服务就可以完成对插件的升级。

 

Openfire插件


Openfire 对插件的目录结构进行了指定,需要按照它的目录结构对插件进行打包,便于Openfire对插件进行管理,插件的目录结构如下:

 


 

myplugin/

 |- plugin.xml      <- Plugin definition file

 |- readme.html     <- Optional readme file for plugin, which will be displayed to end users

 |- changelog.html  <- Optional changelog file for plugin, which will be displayed to end users

 |- logo_small.gif  <- Optional small (16x16) icon associated with the plugin (can also be a .png file)

 |- logo_large.gif  <- Optional large (32x32) icon associated with the plugin (can also be a .png file)

 |- classes/        <- Resources your plugin needs (i.e., a properties file)

 |- database/       <- Optional database schema files that your plugin needs

 |- i18n/           <- Optional i18n files to allow for internationalization of plugins.

 |- lib/            <- Libraries (JAR files) your plugin needs

 |- web             <- Resources for Admin Console integration, if any

     |- WEB-INF/

         |- web.xml           <- Generated web.xml containing compiled JSP entries

         |- web-custom.xml    <- Optional user-defined web.xml for custom servlets

     |- images/


 


在整个目录结构中,plugin.xml对插件进行了定义,PluginManager也是根据这个文件对插件进行管理,包括版本的判断,资源的加载,插件实例化,注册插件的servlet,数据库的管理,将插件的web菜单页面加载到portal(我认为openfire core提供了一种portal的概念,虽然不是严格意义上的)中。

plugin.xml的定义如下:

 


 

 

<?xml version="1.0" encoding="UTF-8"?>

<plugin>

    <!-- Main plugin class -->

    <class>org.example.ExamplePlugin</class>


    <!-- Plugin meta-data -->

    <name>Example Plugin</name>

    <description>This is an example plugin.</description>

    <author>Jive Software</author>


    <version>1.0</version>

    <date>07/01/2006</date>

    <url>http://www.igniterealtime.org/projects/openfire/plugins.jsp</url>

    <minServerVersion>3.0.0</minServerVersion>

    <licenseType>gpl</licenseType>


    <!-- Admin console entries -->

    <adminconsole>

        <!-- More on this below -->

    </adminconsole>

</plugin>

 

 


 

 

其中字段的解释:

  •  
    • class: 插件的入口类,在此类中,必须实现Plugin这个interface。
    • name: 插件的名字
    • description: 插件的描述。 会出现在插件的管理页面中。
    • author: 插件的作者,同description
    • version: 插件版本, 同上
    • date: 插件的开发日期,同上
    • miniServerVersion: 插件需要Openfire平台的最低版本号,在插件装载过程中,平台判断插件的版本号是否匹配,如果不匹配,则不加载。
    • adminconsole: 这个标签指定了插件在Openfire平台中的web入口菜单,openfire会根据这个文件来动态的生成多级入口菜单,这个在后续会继续解释。

 

在开发好插件并调试完成后,将插件打包成为jar或者zip,上传到openfire管理平台中,openfire会自动加载你的插件。

好了,截止目前为止,基本上是翻译openfire的插件开发指南,别说翻译简单,可也是个体力活,很消耗卡路里,有点累了,后续blog中我会分析内部代码的实现。

 

参考页面:http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-dev-guide.html

 

格式貌似很乱, 完整的pdf格式下载

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值