First steps with Knopflerfish
It's a bit easier to discuss things when you know your enemy, so I tried out Knopflerfish.
- fancy desktop interface
- eclipse plugin
- many included bundles
- some kind of convenient
- seems to be quite active
- there is some documentation
So this is not a vote against Felix. I'm quite convinced that James should ship with Felix when we would move to OSGi. But for first development Knopflerfish seems to be an easier starting point. And an OSGi compliant app should run in both.
Following A Tutorial
I downloaded the full-distro and followed the following tutorial http://www.knopflerfish.org/tutorials/osgi_tutorial.pdf using the eclipse plugin in parallel. The learning-curve was really flat and it didn't took much time to get the first examples running. This tutorial seems to be quite useful too: http://oscar-osgi.sourceforge.net/tutorial/
The Eclipse Plugin
For the plugin you have to setup the preferences to define which framework you want to use: http://www.knopflerfish.org/eclipse_preferences.html
Sometimes the plugin has some edges and is a bit tricky but it is all in all very useful. It lets you:
- configure your bundle manifest
- automatically build your bundle to the out/ directory
- OSGi requires you to define the packages you want to use. The plugin sets the classpath accordingly, so you can't forget.
- run/debug everything inside eclipse
You can add additional bundles to your eclipse run configuration to have access to a console or even the desktop. One problem I ran into was adding xml files to the bundle. It is configured to only include .java/.class by default.
1. in Project/Proterties/Java Build Path/Source: Indluded **/*.xml 2. you have to manually edit .bundle-pack
<?xml version="1.0" encoding="UTF-8"?> <bundlejar> <resource dst="" pattern=".*\.xml|.*\.class" src="/fms_mailgenerator/out" type="0"/> </bundlejar>
Adding an additional <resource> tag didn't work, it was ignored.
Using the Knopflerfish Desktop is great when you want to try out starting/stopping/install/update/remove bundles. Using the mouse is really convenient here and it is as easy as running inside eclipse if you don't need debugging.
Once you started Knopflerfish by something like java -jar framework.jar you can simply add your just created bundles from workspace/your-bundle/out/your-bundle-1.0.0.jar and play around with starting and stopping. And when you have changed something in eclipse you simply press the "Update Bundle" because the bundle in out/ is always up-to-date!
Now try on your own!