Thursday, November 11, 2010

Description of OSGI Layer

OSGI is the frame work which helps developer to maintain more than one version of jar/JAVA class file on same server. It provide API that help the developer for deploying run time java /JAR files as bundle in the frame work without need of restarting the server.

Any framework that implements the OSGi standard provides an environment for the modularization of applications into smaller bundles. Each bundle is a tightly-coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).

The framework is conceptually divided into the following areas:


Bundles are normal jar components with extra manifest headers.


The services layer connects bundles in a dynamic way by offering a publish-find-bind model for plain old Java objects (POJO).

Services Registry

The API for management services (ServiceRegistration,ServiceTracker and ServiceReference).


The API for life cycle management for (install, start, stop, update, and uninstall) bundles.


The layer that defines encapsulation and declaration of dependencies (how a bundle can import and export code).


The layer that handles the security aspects by limiting bundle functionality to pre-defined capabilities.

Execution Environment

Defines what methods and classes are available in a specific platform. There is no fixed list of execution environments, since it is subject to change as the Java Community Process creates new versions and editions of Java. However, the following set is currently supported by most OSGi implementations:


Bundles are the collection of java files or JAR files.

Services provide the way to handle this jar/java file dynamically.

Services Registry the API for management services

Life-Cycle provide the API for life cycle management which include the install, uninstalled , start, stop of the bundle.

Modules this layer deals with how a bundle can import and export code.

Security this layer that handles the security aspects


Q) How to run equinox through Java Program so that we can call deployed OSGI jar thorough java class

Ans: Use following code


import org.eclipse.core.runtime.adaptor.EclipseStarter;

import org.osgi.framework.Bundle;

import org.osgi.framework.BundleContext;

public class TestStartEquinox {

public static void main(String args[]) throws Exception {

//String[] equinoxArgs = {"-console","1234","-noExit"};

String[] equinoxArgs = {"-console","","-noExit"};

//String[] equinoxArgs = {"-os ${target.os} -ws ${} -arch ${target.arch} -nl ${} -console","1234","-noExit"};

//String[] equinoxArgs = {"","",""};

BundleContext context = EclipseStarter.startup(equinoxArgs,null);


//URL bundleContent = new URL("reference:file:/C:/Test/toelete/plugins/ToDeleteOSGI_1.0.0.201011121510.jar");

//Bundle bundle = context.installBundle("initial@file:/C:/Test/toelete/plugins/ToDeleteOSGI_1.0.0.201011121510.jar",bundleContent.openStream());

Bundle bundle = context.installBundle("file:/C:/Test/toelete/plugins/ToDeleteOSGI_1.0.0.201011121510.jar");


Bundle bundle1[] = context.getBundles();

for(int i =0; i






- The above code is used to installed new bundle i.e. OSGI jar file named as ToDeleteOSGI_1.0.0.201011121510.jar in equinox container in addition of starting the container using java class.

Q) How to create OSGI executable jar i.e. bundle jar like ToDeleteOSGI_1.0.0.201011121510.jar from the existing OSGI project.

Ans: First create an OSGI project. I had used Eclipse plug in for the same. let give it name as ToDeleteOSGI. Once the project is created click on the project folder i.e. in Package Explorer

File >> Export >> Plug-in Developemnt >> Deployable plug-ins and fregments >> next >> check/verify the project that we want to make the executable jar , Give the Directory name > Finish.

No comments: