Setting up the library project
Create a new java project that will host your library, this will be our foo4j lib. Make sure you create a proper project layout (folder structure) for you project, in order for the ant buildfile in step 3 to work.
- Create a foo class with two dummy methods like this:
package net.java.foo4j;
public class Foo {
public void helloWorld() {
System.out.println("Hello World!");
}
public void byeWorld() {
System.out.println("Bye World!");
}
} - Create a build.xml (ant buildfile) like the one bellow to produce a foo4j.jar file and build the project.
<?xml version="1.0" ?>
<project default="main" name="otr4j">
<property name="src.dir" value="src" />
<property name="build.dir" value="bin" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.dir" value="${build.dir}/jar" />
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="main" depends="compile, compress"
description="Main target">
<echo>
Building the .jar file.
</echo>
</target>
<target name="compile" description="Compilation target">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" />
</target>
<target name="compress" description="Compression target">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar"
basedir="${classes.dir}" />
</target>
</project>
Setting up SipCommunicator
Our plugin will be build as an OSGi bundle. What helped me understand OSGi, is Clement Escoffier's paper "Developing an OSGi-like service platform for .NET", just skip all the .NET stuff.
In this paper you can find a high level overview of the OSGi framework. there are various sources on the web that can help you better
understand OSGi once you get the high level picture.
For the purpuses of this mini-guide, our strategy will be to build an OSGi bundle, and plug it into SipCommunicator. This OSGi -plugged in SipCommunicator- bundle will be our plugin, so I may use the term bundle and plugin interchangibly.
- Edit the properties of SipCommunicator project and add foo4j project in the Java Build Path.
- Create a class (FooActivator) that will implement the BundleActivator Interface. This class will handle the starting and stopping of our plugin.
package net.java.sip.communicator.plugin.foo;
import org.osgi.framework.BundleActivator;
import net.java.foo4j.Foo;
public class FooActivator implements BundleActivator {
@Override
public void start(BundleContext arg0) throws Exception {
Foo foo = new Foo();
foo.helloWorld();
}
@Override
public void stop(BundleContext arg0) throws Exception {
Foo foo = new Foo();
foo.byeWorld();
}
} - Create the manifest for you bundle
Pay attention that our bundle exports the net.java.foo4j package.
Bundle-Activator: net.java.sip.communicator.plugin.otr.FooActivator
Bundle-Name: The infamous foo plugin!
Bundle-Description: A plug-in that will help burgers accomplish their master plan to rule the world.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Export-Package: net.java.sip.communicator.plugin.foo,
net.java.foo4j,
Import-Package: net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
net.java.sip.communicator.util,
org.osgi.framework - Edit SipCommunicator's build.xml and add an ant build target for our bundle
Make sure that you change PATH_TO_FOO4j_PROJECT
<!-- BUNDLE-PLUGIN-OTR -->
<target name="bundle-plugin-otr">
<!-- Creates a bundle for the plugin OTR.-->
<jar compress="false" destfile="${bundles.dest}/otr-plugin.jar"
manifest="${src}/net/java/sip/communicator/plugin/otr/otr.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/otr"
prefix="net/java/sip/communicator/plugin/otr"/>
<zipfileset dir="PATH_TO_FOO4j_PROJECT/bin/jar/foo4j.jar"
prefix="net/java/foo4j"/>
</jar>
</target>
to something meaningful.
We're done, now you should be able to debug SipCommunicator as it described in the official guide here.