Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is the continuation of the OSGi introduction and the OSGi exercise 1

Exercise 2

In this second exercise we’ll learn the usage of feature and update site.

We will

1. create a bundle

2. create a feature

3. create an update site

4. install from the update site

5. do some operations on the OSGi console

Create bundle

First, we go back to our bundle-development and we develop a new bundle,


In the Activator-class, we modify the start() and stop() methods:

The start() method:

System.out.println("==> Hello, this is a demo: " +  bundleContext.getBundle().getSymbolicName() + " - " + bundleContext.getBundle().getVersion());

The stop() method:

System.out.println("==>End of demo.");

Note that we don’t export the bundle.

Create feature

Create new Project of type Feature Project:

File -> New -> Project -> Plug-in Development -> Feature Project

Enter a name (this is only the name of the project in Eclipse) and the details which will describe the feature:

Press Next.

On the next page, you select the bundles which will be part of the feature.

Search for the bundle we've created in step 1, e.g.

Select it.

Our new feature will consist of only one bundle.

Press Finish.

The feature project is created and the feature.xml file, which describes the feature, is automatically opened.

Check the details.

Open the tab Plug-ins and check that our example plug-in is listed.

You may wonder why the version of the plug-in is set as 0.0.0

The reason is that in a productive environment, the exact version is determined on build-time.

But for our exercise, let’s explicitly set the version to the new version of our example bundle.

Press the button Versions… and then select the second radio-button Copy versions from plug-in… manifest

Ensure that the checkbox on the right pane, Unpack the plug-in after the installation is not enabled.

The reason is that typically we’d like to have all bundles packed as jar files in the plugins folder.

See screenshot:

The tab Dependencies should be edited.

On Feature level, it is possible to define dependencies, which is an aggregation of the dependencies of each contained plugin.

Since collecting all dependencies would be too much effort for a human, this work can be delegated to the machine by pressing the Compute button.

It makes sense to enable the checkbox Recompute when … plug-ins change, because typically the versions of plug-ins change during development.

Create Update Site

Start the wizard via File -> New -> Project -> Plug-in Development -> Update Site Project

Enter a name for the project and – why not – enable the Web Resource generation

Regarding the location:

for certain reason (there’s no export), I’d prefer to specify a location outside the workspace,

e.g. C:\myTempWorkspace

Open the site.xml file, if not opened automatically.

Create an own category – why not? – by pressing the button New Category.

Select the entry and provide Details for the new category in the right pane: the ID and the Name:

Select the entry and press Add Feature.

In the dialog Filter Selection, start typing mydemo into the field (which is a filter field),

then choose our example feature from the list.

Press OK


the feature is added under the category, as specified:

Until now, we’ve only defined the update site (including the category and the feature that we offer in our update site), but it cannot be consumed yet.

So, the next logical step would be to export our Update Site, but there’s no export wizard available.

Instead, we have a Build button in the editor, which has to be used.

If not open, open the editor via double-click on the file site.xml.

In the tab Site Map, press the button Build All and wait a few seconds.

The result can be seen in the Project Explorer in Eclipse or in the local file system:

The feature jar has been built.

The bundle jar has been built.

The artifacts.jar and the content.jar has been generated

So this is the expected result, an update site that could be copied to a web server in order to allow users all over the world to install our bundle.

Install from Update Site

In Eclipse, we change to the OSGi console.

In order to make sure what is installed, type

lb mydemo

The result is “No matching bundles found”

That’s expected, since we haven’t installed it.

Now we’ll install from our newly built Update Site

In Eclipse, press Window -> Preferences -> Install/Update -> Available Software Sites

In the right pane, press Add…

In the dialog, press Local… and navigate to the location of our update site root folder (in our example: file:/C:/myTempWorkspace/ )

Enter a name in order to recognize this entry, e.g. MySoftwareSite and press OK

Exit the Preference page with OK.

Now that we’ve specified a software site in our Eclipse, we can install from there (Note that this could as well have been done in one step).

Press Help -> Install New Software

In the “Work With” – drop down, choose this software site. 

What the wizard does right now is to parse the site.xml of the specified software site and present all features, that are found, in the list below.

In our example, there’s only one feature:

Make sure that the checkbox Group items by category is enabled, such that you can see our own defined category.

Step through the wizard, finish it and restart Eclipse.

Work with the bundle

Now we proceed as usual:

Check that the bundle MyDemoBundle has been installed and that it can be started.


At the end of the exercises, you’ve created bundle, feature, category, update site, p2-repository.

You’ve exported OSGi artifacts and used then in Equinox (in Eclipse)

You’ve used OSGi commands.

You've touched almost everything that's available.

Are you satisfied?