+

Search Tips   |   Advanced Search

Develop an OSGi bundle with simple activation

The most straightforward way to control the lifecycle of our OSGi bundle code is to implement the org.osgi.framework.BundleActivator interface in one of the classes within the bundle. When the server starts and stops the bundle, the start and stop methods of the BundleActivator interface are called.

If we are using the WebSphere Application Server Developer Tools, create an OSGi bundle project, and create an OSGi BundleActivator class in that project. Then identify the bundle activator class to the OSGi framework by adding the Bundle-Activator header to the bundle MANIFEST.MF file. For example: Bundle-Activator: com.example.bundle.Activator.


Subtopics


Example

package com.example.bundle;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {
 public void start(BundleContext context) throws Exception {
  System.out.println("Sample bundle starting");
  // Insert bundle activation logic here
 }

 public void stop(BundleContext context) throws Exception {
  System.out.println("Sample bundle stopping");
  // Insert bundle deactivation logic here
 }
}


Parent topic: Develop a Liberty feature