LibraryLink ToToggle FramesPrintFeedback

OSGi Bundles

With OSGi, you modularize applications into bundles. Bundles are the logical modules that together comprise an application. Each bundle is a tightly-coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare any external dependencies. In OSGi, a bundle is the primary deployment format. Bundles are applications that are packaged in JARs and can be installed, started, stopped, updated, and removed.

OSGi provides a dynamic, concise and consistent programming model for developing bundles. Development and deployment are simplified by decoupling the service's specification (Java interface) from its implementation.

The OSGi bundle abstraction allows modules to share Java classes. This is a static form of reuse. The shared classes must be available when the dependent bundle is started.

A bundle is a JAR file with metadata in its OSGi manifest file. A bundle contains class files and optionally other resources and native libraries. You can explicitly declare which packages in the bundle are visible externally (exported packages). You can also declare which external packages a bundle requires (imported packages).

The OSGi Framework is the runtime that implements the OSGi functionality and provides a standardized mechanism for packaging and managing application bundles. The OSGi Framework layers form the container in which you install bundles. The OSGi Framework manages the installation and updating of bundles in a dynamic, scalable manner.

The Module layer handles packaging and sharing Java packages between bundles and hiding packages from other bundles. The OSGi Framework dynamically resolves dependencies among bundles and performs bundle resolution to match imported and exported packages and can manage multiple versions of a deployed bundle.

OSGi uses a graph model for class loading rather than a tree model (as in Java). Bundles can share and re-use classes in a standardized manner with no runtime class-loading conflicts.

Each bundle can also have its own internal classpath, so that it can serve as an independent unit if required.

The benefits of class loading in OSGi include:

  • Sharing classes directly between bundles. There is no requirement to promote JARs to a parent class-loader.

  • You can deploy different versions of the same class at the same time, with no conflict.

The remainder of this guide describes how to use OSGi bundles:

  1. Package components into bundles. See Packaging OSGi Bundles. You can use Maven or Eclipse OSGi tooling to simplify bundle creation. See Using Maven OSGi Tooling and Using Eclipse OSGi Tooling.

  2. Create or browse federated collections of bundles. See Using OSGi Bundle Repositories.

  3. Install complex applications by grouping bundles into features according to functionality. See Provisioning OSGi Features.

  4. Deploy bundles in an OSGi container. See Hot Deployment.

  5. Start, stop, and dynamically update bundles. See Lifecycle Management.

  6. Use optional JAAS-based OSGi security. See Securing OSGi Bundles.