OSGi
Back to current versionRestore this version

OSGi#

Open Services Gateway Initiative

Resources#

OSGi Tutorial#

I started a simple exercise (see OSGi In Practice above).

Starting with Eclipse Kepler, downloaded the Equinox runtime first from http://download.eclipse.org/equinox/. Unzip it to /usr/local/equinox-sdk-keplersr1.

Then add the Equinox named User Library to Eclipse, pointing to /usr/local/equinox-sdk-keplersr1/plugins/org.eclipse.osgi_3.9.1.v20130814-1242.jar .

Create a new Java project named "OSGi Tutorial", and make sure you use the above User Library.

Create a new runtime configuration, new Java Application, enter search this should find org.eclipse.core.runtime.adaptor.EclipseStarter and program arguments -console -configuration runtime. However, this does not work, you have to add the -consoleLog, or the (error) logging will go to a file by default.

You also need a configuration/config.ini file with (example) the following contents to be able to run a basic OSGi runtime:

# contents of config.ini
osgi.bundles=\
/usr/local/equinox-sdk-keplersr1/plugins/org.apache.felix.gogo.command_0.10.0.v201209301215.jar,\
/usr/local/equinox-sdk-keplersr1/plugins/org.apache.felix.gogo.runtime_0.10.0.v201209301036.jar,\
/usr/local/equinox-sdk-keplersr1/plugins/org.apache.felix.gogo.shell_0.10.0.v201212101605.jar,\
/usr/local/equinox-sdk-keplersr1/plugins/org.eclipse.equinox.console_1.0.100.v20130429-0953.jar,\
/usr/local/equinox-sdk-keplersr1/plugins/org.eclipse.osgi_3.9.1.v20130814-1242.jar@-1:start

All parameters for the config.ini are documented on the Eclipse Help platform

Install the bndtools from Eclipse update site http://bndtools-updates.s3.amazonaws.com/

Create the HelloWorldActivator.java file :

package org.osgi.tutorial;

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

public class HelloWorldActivator implements BundleActivator {
	public void start(BundleContext context) throws Exception {
		System.out.println(" Hello , World ! ");

	}

	public void stop(BundleContext context) throws Exception {
		System.out.println(" Goodbye , World ! ");
	}
}
&&

And the helloworld.bnd file (in root of project) :

# helloworld . bnd
Private-Package: org.osgi.tutorial
Bundle-Activator: org.osgi.tutorial.HelloWorldActivator
Bundle-Version: 1.0
Bundle-Name: HelloWorld Sampletje
Bundle-Description: Wat een prachtvoorbeeld !
Bundle-Category: Tutor
Bundle-License: Apache
Bundle-Vendor: DirtyHarry
Bundle-ContactAddress: NL
Bundle-DocURL: http://www.computerhok.nl