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.
Easy? You want easy?
ReplyDeleteIn 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.
Not that easy! ;-)
ReplyDeleteCoding it yourself (albeit using cut and paste), removes any sense of 'smoke and mirrors'.
:-)
ReplyDelete--- >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?
perfect
ReplyDeleteNB the manifest should have:
ReplyDeleteImport-Package: org.osgi.framework;version=1.3.0
since Equinox 3.3 has more strict checking than Equinox 3.2 did.
Just a "nit"...
ReplyDeleteThe jar command should be:
jar cfm HelloWorld.jar Manifest.MF HelloWorld.class
Thanks Kit.
ReplyDelete