OSGi Hello World with NetBeans 6.9

Since version 6.9, NetBeans offers the possibility to work with OSGi bundles. The creation of the project is relatively simple. You just need to go to new Project > Maven > Maven OSGi Bundle like this :

The generated pom.xml begins this way:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 <name>OSGiTest OSGi Bundle</name>


We notice there is only one dependency to the OSGi core and that the packaging is “bundle”. The rest of the pom is the run-on-felix profile configuration for NetBeans.

To display a HelloWorld in Apache Felix console, we need to add a HelloWorld java class. So, right-click on the source package and go to New > Other > OSGI > Bundle Activator like this :

Here is the code for the class after adding something for the console :

package net.stephou.osgi;

import org.osgi.framework.BundleActivator;

import org.osgi.framework.BundleContext;



* @author Stephou


public class HelloWorld implements BundleActivator {

   public void start(BundleContext context) throws Exception {

     System.out.println("Hello OSGi World");


   public void stop(BundleContext context) throws Exception { 

     System.out.println("Goodbye OSGi World");


In the pom.xml, you can see the Bundle-Activator line has been added for the maven-bundle-plugin :


Just Build and Run your project in NetBeans and you’ll see the following in the console :

Welcome to Felix

Hello OSGi World

Congratulation 😉