What is OSGi and what are some examples of its use?

Zac picture Zac · Jan 2, 2011 · Viewed 11.6k times · Source

I've just started hearing the term OSGi being used (while reading tutorials on common Java EE containers such as GlassFish and Spring), however I have been unable to find a simple, straight-forward, easy-to-understand explanation of what OSGi is that an enterprise novice such as myself would understand.

Can someone provide such a dummy-proof explanation? Maybe with some examples or even code excerpts?

Thanks!

Answer

Andreas Kraft picture Andreas Kraft · Jan 3, 2011

Simply said, OSGi is a dynamic module system for Java. It defines means to install, uninstall, update, start and stop modules. Those modules are called bundles, but are, in their simplest form, actually Java jar files with a special Manifest. Modules can be installed, uninstalled etc without stopping or restarting the Java VM.

An OSGi framework manages the described lifecycle of and dependencies between the bundles in a secure way. A bundle needs to state which Java packages it exports and which it imports. The import and export statements can be annotated with version information, so that you even can have more than one version of the same package in the same Java VM.

The OSGi Alliance is the organization that specifies the OSGi framework and many accompanying services, e.g. for managing configuration data, device access, etc.

This is just a very basic overview. OSGi is much more. Please have a look at https://www.osgi.org/developer/architecture/ (an introduction to OSGi's architecture) and https://www.osgi.org/developer/where-to-start/ (a lot of links and further readings recommended by the OSGi Alliance).