Now that we have Eclipse and Knopflerfish installed let's get into some code. This OSGi bundle will roll a random six-sided die every second and print the result to the Knopflerfish Desktop console.
Click File -> New Project and select OSGi Bundle
Fill in the project information, I am going to call this project RandomRoll.
This is the OSGi specific information, make sure you check the "Create Activator" class box (More on this later.)
The manifest file contains all of the OSGi required information for your bundle. The Eclipse OSGi plugin has a built-in editor for the bundle.manifest file to make editing it a little easier on you.
Your default bundle.manifest file should look like this.
This is where the logic of our OSGi application lies. We'll treat the RandomRoll class just like any other class. The only OSGi requirement is that RandomRoll must extend java.lang.Thread.
Activator.start() will run when the bundle is executed by Knopflerfish. And -as I'm sure you can guess- Activator.stop() will get executed when the bundle is finished executing (when you click the stop button.)
This is my least favorite part of Java programming, I think the deployment of .jar files is tedious at best and it's really annoying to have.... wait... what's that... the .jar bundle for RandomRoll is already built for me? Nice! Simply look in the
Speaking of... now it's time to move on to the final stage of this tutorial and run our new OSGi bundle.
This is Part 2 of a 3 part introduction to OSGi and Knopflerfish.
SOA OSGi Development with Knopflerfish – Part 1: The Setup
SOA OSGi Development with Knopflerfish – Part 2: The Code
SOA OSGi Development with Knopflerfish – Part 3: The Execution