2.3 The Anatomy of a Bundle
A bundle is a self-describing collection of files, as shown in Figure 2-4.
Figure 2-4 Bundle anatomy
The specification of a bundle's contents and requirements is given in its manifest file, META-INF/MANIFEST.MF. The manifest follows the standard JAR manifest syntax but adds a number of OSGi-specific headers. The manifest for the org.equinoxosgi.toast.backend.emergency bundle from the figure looks like this:
org.equinoxosgi.toast.backend.emergency/MANIFEST.MF Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.equinoxosgi.toast.backend.emergency Bundle-Version: 1.0.0 Import-Package: javax.servlet;version="2.4.0", javax.servlet.http;version="2.4.0", org.equinoxosgi.toast.core;version="1.0.0", org.equinoxosgi.toast.core.emergency;version="1.0.0", org.osgi.service.component;version="1.0.0", org.osgi.service.http;version="1.2.0" Export-Package: org.equinoxosgi.toast.backend.emergency.internal; version="1.0.0";x-internal:=true, org.equinoxosgi.toast.backend.emergency.internal.bundle; version="1.0.0";x-internal:=true Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-Copyright: Copyright (c) 2009 equinoxosgi.org Bundle-Name: Toast Back End Emergency Bundle-Vendor: equinoxosgi.org
All bundle manifests must have the headers Bundle-SymbolicName and Bundle-Version. The combination of these headers uniquely identifies the bundle to OSGi frameworks, developers, and provisioning systems. A bundle also expresses its modularity through headers such as Export-Package, Import-Package, and Require-Bundle. Additional headers such as Bundle-Copyright, Bundle-Name, and Bundle-Vendor are purely documentation. Throughout the book we'll introduce additional headers as they arise in the tutorial.
A bundle can contain Java types, native libraries, or other, nonexecutable files. The content and structure of a bundle depend entirely on what it is delivering and how it is being used. Most bundles deliver Java code to be executed by a Java runtime. These are structured as JARs with the Java code in a package-related folder structure (e.g., org/equinoxosgi/toast/core/Delay.class).
Bundles that deliver non-Java content (e.g., source, documentation, or static web content) are structured to suit the mechanism consuming their content. For example, native executables and files being accessed from other programs must reside directly on disk rather than nested inside JAR files. OSGi framework implementations such as Equinox facilitate this by supporting folder-based bundles. Folder-based bundles are essentially just JAR bundles that have been extracted.