Tuesday, February 06, 2007

Knopflerfish OSGi tutorial

Thanks to some Australian OSGi users for providing a nice link to a Knopflerfish OSGi tutorial.

My example of how to create an OSGi bundle in under 10 minutes still takes some beating for simplicity (or triviality, if you prefer), but I do believe in giving beginners a really easy way in. If they're smart, they'll soon catch on.

7 comments:

  1. Easy? You want easy?

    In Knopflerfish, go to 'File->Open URL'. Then paste in http://www.bandlem.com/HelloWorld.jar.

    Lo, it says Hello world. Stop it, it says Goodbye World. Start it again, and it says Hello world.

    Now that's easy.

    PS You really shouldn't install remote code; you never know what it's doing ;-) But it comes with full source (ahem, one class) in case you want to build it yourself.

    ReplyDelete
  2. Not that easy! ;-)

    Coding it yourself (albeit using cut and paste), removes any sense of 'smoke and mirrors'.

    ReplyDelete
  3. :-)

    --- >8 --- HelloWorld.java
    import org.osgi.framework.*;
    public class HelloWorld implements BundleActivator {
    public void start(BundleContext context) {
    System.out.println("Hello World");
    }
    public void stop(BundleContext context) {
    System.out.println("Goodbye World");
    }
    }
    --- >8 --- Manifest.MF
    Manifest-Version: 1.0
    Bundle-Name: HelloWorld
    Created-By: Alblue
    Bundle-Activator: HelloWorld
    Bundle-SymbolicName: HelloWorld
    Bundle-Version: 1.0.0
    --- >8 ---
    javac -cp framework.jar HelloWorld.java

    jar cfm Manifest.MF HelloWorld.class

    Better?

    ReplyDelete
  4. NB the manifest should have:

    Import-Package: org.osgi.framework;version=1.3.0

    since Equinox 3.3 has more strict checking than Equinox 3.2 did.

    ReplyDelete
  5. Just a "nit"...

    The jar command should be:

    jar cfm HelloWorld.jar Manifest.MF HelloWorld.class

    ReplyDelete