How to Create OSGI Bundle in Eclipse IDE

Create OSGI Bundle in Eclipse

Creating OSGI Project

Step 1: Go to the File menu -> Go to Other… -> Select the Plug-in-Project under the Plugin-in-Development in the wizard.

How to Create OSGI Bundle in Eclipse

Step 2: Give name for your project and make sure you are selecting target platform is an OSGI Framework in the wizard.

How to Create OSGI Bundle in Eclipse

Step 3:

How to Create OSGI Bundle in Eclipse

Step 4:

How to Create OSGI Bundle in Eclipse

Step 5:

How to Create OSGI Bundle in Eclipse

Step 6:

How to Create OSGI Bundle in Eclipse

Project Structure

How to Create OSGI Bundle in Eclipse

Activator.java

package com.dineshkrish;

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

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class Activator implements BundleActivator {

	public void start(BundleContext context) throws Exception {
		System.out.println("Hello Everyone - Bundle is started!!!");
	}

	public void stop(BundleContext context) throws Exception {
		System.out.println("Goodbye Everyone - Bundle is stoped!!!");
	}

}

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MyBundle
Bundle-SymbolicName: MyBundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.dineshkrish.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-ActivationPolicy: lazy

Running the bundle

How to Create OSGI Bundle in Eclipse

Output

How to Create OSGI Bundle in Eclipse

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.