openfire

来源:互联网 发布:win8.1系统优化 编辑:程序博客网 时间:2024/05/07 11:33
插件开发
首先导包jasper-compiler.jar包
                jasper-runtime.jar包
                openfire.jar包
                servlet.jar包
如果没有包,可用ant在openfire源码中build出来


创建源码目录必须是src/plugins/xxxx,插件写在该包
复制changelog.html  log_lareg.png  logo_small.png  readme.html四个文件


写插件实现plugin接口,实现destroyPlugin()    销毁方法
                                                 initializePlugin()  初始化方法
--------------------------------------------------
创建并配置plugin.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<!-- Main plugin class  这里是最重要滴,就是你的插件的全路径-->
    <class>yxx.myplug.MyPlugOne</class>
 
    <!-- 配置插件名,插件描述,插件作者 -->
    <name>PlugOne</name>
    <description>is good</description>
    <author>sony</author>
 
    <version>1.0.0</version>
    <date>10/31/2013</date>
    <minServerVersion>3.7.1</minServerVersion>
    <licenseType>gpl</licenseType>
 
    <adminconsole>        
    </adminconsole>
</plugin>
--------------------------------------------------
创建一个build文件夹,里放build_yxx.properties
                                               build_yxx.xml
分别配置两文件
--------------------------------------------------
build_yxx.properties
 #tomcat home
tomcat.home=D:/tomcat-6.0.30
webapp.path=F:/WorkSpace/WefPlugDemo2
 
plugin.name=PlugOne
plugin.path=F\:/WorkSpace/WefPlugDemo2/src/plugins/myPlug
--------------------------------------------------
 build_yxx.xml 太多了,以后复制就好了


生命周期:服务器启动就执行插件,关闭销毁


-------------------------------------------------------------------------------------
public class MyInterceptorOne implements PacketInterceptor{
实现:public void interceptPacket(Packet packet,...)方法


//添加一个拦截器到插件
MyInterceptorOne myInterceptorOne = new MyInterceptorOne();
InterceptorManager.getInstance().addInterceptor(myInterceptorOne);


------------------------------------------------------------------------------------------
Connection conn = DbConnectionManager.getConnection();
这个连接来操作数据库






----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MySmack相当于聊天机器人


public void start(String name) throws Exception{
//连接配置
ConnectionConfiguration config = new ConnectionConfiguration("localhost",5222);
//创建连接对像
connection = new XMPPConnection(config);
//创建连接
connection.connect();
//登陆
connection.login(name, name);


//添加监听
//监听什么消息类型
PacketFilter filter = new PacketTypeFilter(Message.class);
//监听包
PacketListener listener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
System.out.println(packet.toXML());
Message message = new Message();
message.setType(Type.chat);

message.setTo(packet.getFrom());
message.setFrom(packet.getTo());
message.setBody("hello wordd dddddddddd ");

connection.sendPacket(message);
}
};
//把监听加到连接上
connection.addPacketListener(listener, filter);

Thread.sleep(1000*60);//设置监听时间
//监听结束
connection.disconnect();
}





0 0
原创粉丝点击