Part of the OSGi R4 release, fragments are a very useful and powerful feature. A fragment is “a bundle that is attached to a host bundle”, adding content to the target bundle. A fragment cannot have its own class loader nor a bundle activator and cannot override the information already present in the host. In short, through fragments, bundles can be extender with resources, classes and even manifest entries. To quote the spec again, a “...key use case for fragments is providing translation files for different locales. This allows the translation files to be treated and shipped independently from the main application bundle.”
|For a full description on fragments, please see the OSGi specification, section 3.14.|
In Spring DM, fragments are useful for configuring various components such as the extenders. To do that, simply bundle the resources as you normally would and add an extra entry to the bundle manifest:
Fragment-Host: <host bundle symbolic name>
This line indicates that the containing bundle is a fragment and that it should be attached to the host specified by a symbolic name. The fragment and host bundle symbolic name should be different. For example, to attach a fragment (with extra configuration) the Spring DM extender, one could use the following manifest:
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Fragment-Host: org.springframework.osgi.extender Bundle-SymbolicName: org.mydomain.project.fragment Bundle-Name: my-fragment Bundle-Description: Fragment attached to Spring DM extender
OSGi bundle version. A value of
The symbolic name of the bundle to which this fragment should be attached to. In this case, the value
The fragment symbolic name.
The bundle name - an optional yet useful header.
The bundle description - just like the name, this header is useful for humans not for the OSGi platform itself. However, it is recommended that you define it to help identify the bundle purpose.
|The Manifest entries order does not matter, but they case sensitive.|
When multiple bundles with the same symbolic names are present, one can add the bundle version to make sure the proper wiring is done:
The default value for
bundle-version (when it's not specified) is