Developing an OSGi bundle with simple activation

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

About this task

If you are using the WebSphere® Application Server Developer Tools, create an OSGi bundle project, and create an OSGi BundleActivator class in that project. Then identify your 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.

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
	}
}