An OSGi bundle, which can be a JAR or web application archive (WAR) file, contains a bundle manifest file META-INF/MANIFEST.MF. In addition to the headers that can be defined for a non-OSGi JAR or WAR file, the bundle manifest file for an OSGi bundle contains OSGi-specific headers. The metadata that is specified in these headers enables the OSGi Framework to process the modular aspects of the bundle.
Eclipse tooling provides convenient editors for the manifest file.
Here is an example bundle manifest file,
META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MyService bundle
Bundle-SymbolicName: com.sample.myservice
Bundle-Version: 1.0.0
Bundle-Activator: com.sample.myservice.Activator
Import-Package: org.apache.commons.logging;version="1.0.4"
Export-Package: com.sample.myservice.api;version="1.0.0"
Meta-Persistence: entities/persistence.xml,
lib/thirdPartyEntities.jar!/META-INF/persistence.xml
Web-ContextPath: /contextRoot
Bundle-Blueprint: /blueprint/*.xml
The metadata in a
bundle manifest file includes the following headers:
Bundle-SymbolicName![[Updated in September 2011]](../deltaend.gif)
A name that identifies the bundle uniquely.
- Bundle-Version
- This header describes the version of the bundle, and enables multiple
versions of a bundle to be active concurrently in the same framework
instance.
- Bundle-Activator
- This header notifies the bundle of lifecycle changes.
- Import-Package
- This header declares the external dependencies of the bundle that
the OSGi Framework uses to resolve the bundle. Specific versions or
version ranges for each package can be declared. In this example manifest
file, the org.apache.commons.logging package is
required at Version 1.0.4 or later.
- Export-Package
- This header declares the packages that are visible outside the
bundle. If a package is not declared in this header, it is visible
only within the bundle.
- Meta-Persistence
- If your application uses the Java Persistence
API (JPA), and this bundle is a persistence bundle, then the bundle
manifest also contains a Meta-Persistence header. For more information,
see JPA and OSGi Applications.
- This header lists all the locations of persistence.xml files in the persistence bundle. When this header is present, the default location, META-INF/persistence.xml, is added by default. Therefore, when the persistence.xml files are in the default location, the Meta-Persistence header must be present, but its content can be empty (a single space).
- Web-ContextPath
- The presence of this header identifies this bundle as a web application
bundle.
This header specifies the default context from which the
web content is hosted.
- Bundle-Blueprint
- This header specifies the location of the blueprint descriptor
files in the bundle; for more information, see Section 121.3.4 of
the OSGi Service Platform Release 4 Version 4.2 Enterprise
Specification.