Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

After implementing the Java source code for the bundle, we must also define a manifest file that contains meta-data needed by the OSGi framework for manipulating the bundle. The manifest is packaged into a JAR file along with the Java class file associated with our bundle; the whole JAR package is actually referred to as a bundle. We create a file called manifest.mf that contains the following:

Code Block
Bundle-Activator: tutorial.example1.Activator
Bundle-Name: Service listener example
Bundle-Description: A bundle that displays messages at startup and when service events occur
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: tutorial.example1.Activator
Import-Package: org.osgi.framework

Most of the above meta-data is for human consumption and does not affect the OSGi framework. Only the first piece of Bundle-Activator and Import-Package meta-data , Bundle-Activator, is used by the framework. This The Bundle-Activator attribute tells the framework which class implements the BundleActivator interface. As a result of With this information, when the OSGi framework starts the bundle, an instance of the specified class is created and its start() method is invoked. The created instance will also have its stop() method called when the framework stops the bundle. The Import-Package attribute informs the framework of the bundle's dependencies on external packages; all bundles with an activator must import org.osgi.framework since it contains the core OSGi class definitions. Any packages dependencies will be verified and resolved by the OSGi framework.

Now we need to compile the source code. To compile we must have the felix.jar file (found in Felix' bin directory) in our class path. We compile the source file using a command like:

...