otr4j is part of my GSoC 09' project and is encouraged by the SIP Communicator development. otr4j is an implementation of the OTR (Off-the-Record) protocol in java.

Thursday, April 30, 2009

Create a simple plugin for SipCommunicator with an external library and debug in Eclipse

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 name="main" depends="compile, compress"
    description="Main target">
    Building the .jar file.
    <target name="compile" description="Compilation target">
    <mkdir dir="${classes.dir}" />
    <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" />
    <target name="compress" description="Compression target">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar"
    basedir="${classes.dir}" />

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 {
    public void start(BundleContext arg0) throws Exception {
    Foo foo = new Foo();

    public void stop(BundleContext arg0) throws Exception {
    Foo foo = new Foo();
  • Create the manifest for you bundle

    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,
    Import-Package: net.java.sip.communicator.service.protocol,
    Pay attention that our bundle exports the net.java.foo4j package.
  • Edit SipCommunicator's build.xml and add an ant build target for our bundle

    <!-- BUNDLE-PLUGIN-OTR -->
    <target name="bundle-plugin-otr">
    <!-- Creates a bundle for the plugin OTR.-->
    <jar compress="false" destfile="${bundles.dest}/otr-plugin.jar"
    <zipfileset dir="${dest}/net/java/sip/communicator/plugin/otr"
    <zipfileset dir="PATH_TO_FOO4j_PROJECT/bin/jar/foo4j.jar"
    Make sure that you change PATH_TO_FOO4j_PROJECT
    to something meaningful.

We're done, now you should be able to debug SipCommunicator as it described in the official guide here.

No comments:

Post a Comment

My Commits to SIP Communicator

Mercurial commits to project otr4j on Google Code