Original address: http://www.cnblogs.com/hoojo/archive/2013/03/07/2947502.html
CSDN Address: Http://blog.csdn.net/IBM_hoojo
Follow me step-by-step to develop your own OpenFire plugin
This is a simple plugin development, the next chat recording plug-ins.
Development environment:
System:windows
webbrowser:ie6+, firefox3+
Java EE server:tomcat5.0.2.8, tomcat6
Ide:eclipse, MyEclipse 8
To develop a dependent library:
Jdk1.6, Jasper-compiler.jar, Jasper-runtime.jar, Openfire.jar, Servlet.jar
Email:hoojo_@126.com
Blog:http://blog.csdn.net/ibm_hoojo
http://hoojo.cnblogs.com/
Before beginning, if you do not know how to use OpenFire, install OpenFire server, suggest you read this article:
Http://www.cnblogs.com/hoojo/archive/2012/05/17/2506769.html
Http://www.cnblogs.com/hoojo/archive/2012/05/13/2498151.html One, preparation work
1, download the relevant jar package and OpenFire source code
OpenFire Source Download: http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire_src_3_8_0.tar.gz
Other jar packs can be found in the Lib directory in Tomcat or elsewhere (as mentioned in the steps below).
2. Create your own Java Project project, add the jar package as follows:
Add Jasper-compiler.jar, Jasper-runtime.jar, and Servlet.jar to the new project. If there is no jar first, look at the following steps:
After the download of the OpenFire source directory is like this
If you have an ant tool that can run the ant script directly in the build directory using the DOS command line, you will find a target directory when you run the script. The directory is as follows:
We can find the jar file we need in the Lib directory and add Openfire.jar to your project.
If you don't have ant installed, you can use MyEclipse to copy the build, documentation, and resources directories in the OpenFire source code into a Java project. Then run the build.xml ant script in src in MyEclipse and the same file directory appears.
It is recommended that you set the OpenFire source engineering directory in your myeclipse to this
Among them, Src/plugins/tree is my own writing plug-ins, now can be ignored for the time being. And target is what we need, which contains the OpenFire configuration and the jar package we need. Work is a working directory and is a complete openfire server. If you have not yet downloaded the OpenFire server, you can use this server.
3, understand the OpenFire source code in the plugin
We look for a plugin directory to see, mainly look at the structure inside, the directory structure is very important. Because we will write the plug-in into a jar package, the package of the jar's directory has a certain standard structure, can not easily create other directories.
This is a UserService plug-in, in the Src/java is our plug-in source code, the Web directory is the front-end page, Where Web-custom.xml is the configuration of the current plug-in userserviceservlet configuration; changelog.html is the change log; logo_ Small.gif is the plugin icon; Plugin.xml is the file where we configure Plug-ins, which is very important (here is the hint); second, develop simple plug-ins
The current directory organization of the project is as follows
1, the establishment of their own plug-in class, Sampleplugin.java, inside a simple write-point content.
Package com.hoo.server.plugin;
Import Java.io.File;
Import Org.jivesoftware.openfire.XMPPServer;
Import Org.jivesoftware.openfire.container.Plugin;
Import Org.jivesoftware.openfire.container.PluginManager;
/**
* <b>function:</b> OpenFire Server Plugin sample
* @author Hoojo
* @createDate 2013-2-28 05:48:22
* @file Sampleplugin.java
* @package Com.hoo.server.plugin
* @project Openfireplugin
* @blog Http://blog.csdn.net/IBM_hoojo
* @email hoojo_@126.com
* @version 1.0
*/
public class Sampleplugin implements Plugin {
Private Xmppserver server;
@Override
public void Initializeplugin (PlugInManager manager, File plugindirectory) {
Server = Xmppserver.getinstance ();
System.out.println (Initialize ...) Install the plugin. ");
System.out.println (Server.getserverinfo ());
}
@Override
public void Destroyplugin () {
SYSTEM.OUT.PRINTLN ("Server stopped, destroying Plug-ins.") ");
}
}
Relatively simple, if you install the plug-in on the OpenFire server, the boot server can see the initialization of the content, the shutdown server can see the destruction of the content.
2, configure Plug-ins
<?xml version= "1.0" encoding= "UTF-8"?>
<plugin>
<!--main plugin class here is the most important drop, is the full path of your plugin-->
<class>com.hoo.server.plugin.SamplePlugin</class>
<!--Plugin Meta-data-->
<name>SimplePlugin</name>
<description>this is the My sample plugin.</description>
<author>hoojo</author>
<version>1.0</version>
<date>28/02/2013</date>
<url>http://localhost:9090/openfire/plugins.jsp</url>
<minServerVersion>3.4.1</minServerVersion>
<licenseType>gpl</licenseType>
<adminconsole>
</adminconsole>
</plugin>
Note the configuration of the class above, that configuration is the most important, the configuration is the full path of the plug-in, name is the plug-in names, the plugin name after installation, author is the plugin author; Lincensetype is the protocol; Adminconsole is the page that configures the plug-in's associated , and then speak later.
3, deployable plug-in package JAR directory structure
This is important, and the directory structure will determine the success or failure of your plug-in release.
Before we write the command, we can look at the directory structure of the jar packages for the plug-ins that are already installed in the OpenFire server, and then we will have to pack them into that structure. Must be packaged into such a directory structure, otherwise hem ... The consequences are serious. Statement.
In my machine OpenFire server, the plugin directory in C:\Program Files\openfire\plugins, which has a Search.jar plug-in. Tip: When you install a jar that can be installed in the OpenFire, it will be openfire into the directory structure. Is the same as the effect on the application server published in the war package in Java EE.
The Search.jar directory structure that is typed into a deployable plug-in jar package (equivalent to the directory structure of the published application server) is as follows: