The OSGi framework allows Java developers to create a dynamic component model for their applications. Developers create “bundles” that can be deployed and executed remotely and provide distributed services. The OSGi Framework can act as a Service Oriented Architecture which is not currently available with a vanilla JavaVM environment.
This tutorial will get you set up to create OSGi framework applications with Java. We will be using the Eclipse IDE and the OSGi plug-in to create our bundles as well as the Knopflerfish framework to host and execute them.
If you want to know more about Java modularity, be sure to check out Alex Blewitt's articles on InfoQ.
Eclipse can be downloaded here. I went with the “Eclipse IDE for java Developers” package but it doesn’t really matter which one you choose.
(Windows) Simply extract the downloaded zip file and run eclipse.exe to get started.
Installing the Eclipse OSGi Plugin
Next we’ll install the OSGi plug-in for Eclipse which will make creating bundles much easier, remove the need for using ant, and give us all of the benefits of using the Eclipse IDE to write code (intelli-sense, project management, code generation, etc.)
In Eclipse click Help -> Install New Software Next, click the “Add” button and add the Knopflerfish update site: http://www.knopflerfish.org/eclipse-update/
Once the update site has been added, you should automatically see an option for the Knopflerfish plugin. Check the box and hit “Next” to install. Read the license terms and complete the installation.
Now, we can create OSGi Projects (More on that later)
Now, we need to install the Knopflerfish framework:
java –jar knopflerfish_osgi_
This will open up an installation wizard which will let you set an installation directory.
Finally, we need to run Knopflerfish:
java –jar framework.jar
You should now see the Knopflerfish OSGi Desktop. This is where we will register our bundles and execute them.
Now we’re finally ready to write our first bundle, time to move on to Part 2.
This is Part 3 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