Basics of OSGI - Quick Start for beginners
What on Earth is OSGI?
OSGI framework is a service platform for system of modules or bundles
and provides full interoperability of installed bundles. Bundles are
Java jar files which must implement methods for activation and deactivation
of bundle. Bundles can be installed, started, stopped, updated and uninstalled.
Bundles provide functions (services) to
other bundles. OSGI enables modular architecture of applications, where individual
components (bundles) can be deployed independently of each other.
Many OSGI frameworks exist. Most remarkable are Equinox, Apache
Felix and Knopflerfish. Personally I prefer Knopflerfish, because it is really
easy to set up and it comes with nice graphical interface for managing bundles.
For example, Eclipse IDE is built on Equinox OSGI platform.
Running Knopflerfish OSGI
Download and unzip Knopflerfish OSGI framework to custom directory.
To start Knopflerfish OSGI double click the framework.jar inside the
~/knopflerfish_osgi_version/osgi directory. Alternatively start it from console:
$ java -jar framework.jar
Code examples
Examples are the easiest way to learn OSGI.
► HelloWorld
HelloWorld example is introductory example to writing OSGI applications and provides
information how to build and deploy OSGI bundles.
► CalculatorService
CalculatorService is example how to implement service in OSGI and provide its
functionality to other bundles.
► ServiceListener
ServiceListener example shows how to use listener to receive service events from the framework
when new service that matches given filter is registered.
► ServiceTracker
ServiceTracker example is similar to ServiceListener example. It shows how to implement
ServiceTrackerCustomizer interface which is called when specific service becomes
available or unavailable.