1:新建一个web项目叫做plugin
2:在项目里面新建一个libs 文件夹 ,这个文件夹用来引入jar包。 在这个包里面放入openfire.jar
3:开始编写代码 我新建了两个类
ImInterceptor 代码为:package com.im.plugin;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.Session;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
public class ImInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet, Session arg1, boolean arg2,
boolean arg3) throws PacketRejectedException {
System.out.println("packet:" + packet.toXML());
if (packet instanceof Message) {
Message msg = (Message) packet;
}
}
}
ImPlugin 代码为:
package com.im.plugin;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.Session;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
public class ImInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet, Session arg1, boolean arg2,
boolean arg3) throws PacketRejectedException {
System.out.println("packet:" + packet.toXML());
if (packet instanceof Message) {
Message msg = (Message) packet;
}
}
}
4:这个时候需要通过ant打包 所以在项目线面要写一个build.xml 内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="IM" default="release" basedir=".">
<property name="openfire.path" value="C:/Users/XXX/Desktop" />
<property name="classes.dir" value="classes" />
<property name="lib.dir" value="lib" />
<target name="jar">
<mkdir dir="${classes.dir}" />
<mkdir dir="${lib.dir}" />
<javac srcdir="src" destdir="${classes.dir}">
<classpath>
<fileset dir="libs">
<include name="*.jar" />
</fileset>
</classpath>
</javac>
<jar jarfile="${lib.dir}/grouptreeplugin.jar" basedir="${classes.dir}">
<fileset dir=".">
<include name="*.jar" />
</fileset>
</jar>
<echo message=" iminterceptor ${openfire.path}" />
<jar jarfile="${openfire.path}/groupTreePlugin.jar">
<fileset dir=".">
<include name="lib/*.jar" />
<include name="plugin.xml" />
<include name="build.xml" />
</fileset>
</jar>
</target>
<target name="release" depends="jar">
</target>
</project>
5:还要写一个plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<!-- Main plugin class 这里是最重要滴-->
<class>com.xopenfire.org.DPluginTest</class>
<!-- Plugin meta-data -->
<name>GroupTreePlugin</name>
<description>This is the inttercept plugin.</description>
<author>宋鹏飞</author>
<version>1.0</version>
<date>14/03/2008</date>
<url>http://localhost:9090/openfire/plugins.jsp</url>
<minServerVersion>3.4.1</minServerVersion>
<licenseType>gpl</licenseType>
<!-- Admin console entries -->
<adminconsole>
<!-- More on this below -->
</adminconsole>
</plugin>
6:在ant view 下面 右键 add buidlfile 选中自己项目下的 build.xml 然后双击ant 就开始打包了