Introduction

NetBeans 7.1 was used here. Other versions may do things just a bit differently.

This document assumes that you already have IGB sources checked out and NetBeans set up. If not, go seeĀ Compile and run IGB from the command line.

Create a new plug-in

package com.gene.osgi;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
 * Say hello upon starting, and goodbye when stopping.
 */
public class Installer implements BundleActivator {

    static BundleContext context;

    @Override
    public void start(BundleContext c) throws Exception {
        context = c;
        System.out.printf("%s: starting...\n", this.getClass().getSimpleName());
        javax.swing.JOptionPane.showMessageDialog(null,
            "Hello, World.",
            this.getClass().getSimpleName(),
            javax.swing.JOptionPane.INFORMATION_MESSAGE);
    }

    @Override
    public void stop(BundleContext c) throws Exception {
        javax.swing.JOptionPane.showMessageDialog(null,
            "Goodby, World.",
            this.getClass().getSimpleName(),
            javax.swing.JOptionPane.INFORMATION_MESSAGE);
        System.out.printf("%s: stopping...\n", this.getClass().getSimpleName());
        context = null;
    }

}

Notice that I use a Swing dialog box. Some frameworks (notably Felix) do not automatically import javax classes. So to get Swing imported I had to edit the module manifest. (NetBeans will put this in META-INF/MANIFEST.MF.) Under the Projects tab, open "Module Manifest" in the "Important Files" folder. Add ", javax.swing" to the Import-Package: line like so:

Manifest-Version: 1.0
Bundle-Activator: com.gene.osgi.Installer
Bundle-Localization: com/gene/osgi/Bundle
Bundle-Name: %OpenIDE-Module-Name
Bundle-SymbolicName: com.gene.osgi
Bundle-Version: 1.0
Import-Package: org.osgi.framework, javax.swing

At this point you should be able to run it from NetBeans, but I had trouble doing so. There were a few errors and things hung when I tried to quit, but I did see the "Hello, World" greeting dialog. Also it does work with felix and with IGB.

To get it to work with IGB you will have to use the command line with the install bundle option. For example:

$ ./run_igb.sh -install_bundle file:../../NetBeansProjects/HelloOSGi/build/cluster/modules/com-gene-osgi.jar

Registering

To make a plug in that IGB can actually use we will try to add a track operator similar to MyTransformer in Bundles and Plug-Ins. To do this we will need the com.affymetrix.genometryImpl.operator package which contains an Operator class. So open a new project and open it's properties. You will add genometry.jar as a wrapped jar.

So we create an Activator (which NetBeans likes to name Installer.java) as before, but we add registration code and a new file which extends Operator. It is this new file that needs to be registered and will do the work. The new file is created as a regular java class (not a Module Activator). Let's call it MinOperator.

External Reference