Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

2.4 OSGi Framework

The Eclipse plug-in component model is based on the Equinox implementation of the OSGi framework R4.2 specification (http://osgi.org). You can see it at the bottom of Figure 2-5. In a nutshell, the OSGi specification forms a framework for defining, composing, and executing components or bundles. Think of bundles as the implementation of plug-ins. The term plug-in is used historically to refer to components in Eclipse and is used throughout the documentation and tooling.

Figure 2-5

Figure 2-5 Plug-in manifest

There are no fundamental or functional differences between plug-ins and bundles in Eclipse. Both are mechanisms for grouping, delivering, and managing code. In fact, the traditional Eclipse Plugin API class is just a thin, optional layer of convenience functioning on top of OSGi bundles. To Eclipse, everything is a bundle. As such, we use the terms interchangeably and walk around chanting, "A plug-in is a bundle. A bundle is a plug-in. They are the same thing."

It is convenient to think of the OSGi framework as supplying a component model to Java; that is, think of it as a facility at the same level as the base JRE. OSGi frameworks manage bundles and their code by managing and segmenting their class loading—every bundle gets its own class loader. The classpath of a bundle is dynamically constructed based on the dependencies stated in its manifest. The manifest defines what a plug-in is and on what it depends. All plug-ins are self-describing.

The MANIFEST.MF shown in Figure 2-5 gives the org.eclipse.ui plug-in a plug-in ID, or bundle symbolic name, and a version. Common practice is to use Java package name conventions such as org.eclipse.ui for the identifier and [major.minor.service.qualifier] tuples for the version number. The ID and version are paired to uniquely identify the plug-in. The pairs are then used to express dependency relationships. You can see this in the Require-Bundle header of the manifest—the UI plug-in requires the Runtime, JFace, and SWT plug-ins.

In the context of Eclipse, OSGi's main role is to knit together the installed plug-ins, allowing them to interact and collaborate. The rigorous management of dependencies and classpaths enables tight and explicit control over bundle interactions and thus the creation of systems that are more flexible and more easily composed.

  • + Share This
  • 🔖 Save To Your Account