Hello World Application Using OSGI Bundle

As I always love to write a basic “Hello World” program when ever i start writing something new. So let’s develop a simple OSGI Bundle in which will print “Hello World” and “Goodbye World” to the console when the bundle starts and stops. This will get you started in application development in ODL.

Prerequisites

Before we start developing our component, we should get a running copy of OpenDaylight.  We have used OpenDaylight to run & test this application as it provides a ready to use OSGI Framework. The application written below as such has nothing to do with OpenDaylight.

Creating the Maven Project

Now we start developing our OSGi component. Since OpenDaylight is based on Maven, it is a good idea to also use Maven for our own project. So we start by creating a Maven project for our OSGi component.First, create the following project structure.

This structure is similar to any other bundle in ODL.

Essential to the Maven build process is a so-called Project Object Model (POM) file called pom.xml that you have to create in the folder ~/helloworld

Copy below contents in your pom.xml

Implementation of OSGi Component: The Activator

In order to implement our OSGi component, we only need two class files: an OSGi activator registering our component with the OSGi framework and another file implementing the logic what we want to do in that bundle.

First, we implement the activator by creating the file Activator.java in the directory

Copy below code in Activator.java

Implementation of OSGi Component: The HelloWorld

Copy below code in HelloWorld.java

Here we are just writing 2 functions for displaying “Hello World” and “Goodbye” when our bundle gets start or stop.

Once you are done with the above tiring process. Relax now! Let the OSGI Framework do its magic

Maven will compile and build your code. This will give you output like below in the end ( just pasting last few lines):

Now run the odl ( use ./run.sh, please refer previous blogs if you have forgotten). Once every bundle is up and Active, install your bundle

Check the bundle number of hello world, in my case it’s 269 ( just pasedt last bundle)

Then you can execute the below commands and Eurekaaa!! We are done :)

I know this is just a simple hello world application but yet it will give you the confidence to try ODL out for some more complex applications and help you code your innovative ideas in ODL.

Note: I know this has nothing to do with ODL and no network knowledge is required. But I believe there must be “Hello World” application to get a newbie started, so here is my attempt.

Thanks for reading :)

Comments

  1. says

    Hi, Dear Mohit:
    Thankyou for sharing this good tutorial. But i wonder where is the run.sh ? I cannot find in my code after build the HelloWorld.

  2. Prathibha says

    hi,

    I am getting this following error while running start (i.e 109 in my case)

    Error executing command: Error executing command on bundles:
    Unable to execute command on bundle 109: The bundle “org.opendaylight.controller.helloworld_0.1.0 [109]” could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.dm; version=”[3.0.0,4.0.0)”

    • Gopika says

      gogo bundle exception: The bundle “org.opendaylight.controller.helloworld_0.1.0 [113]” could not be resolved. Reason: Missing Constraint: Import-Package: org.opendaylight.controller.sal.core …. im getting this exception … pls help me in resolving it

  3. says

    This newly established online mobile strike hack tool have risk-free method to accessibility mobile strike
    video game servers and carry out hack with adding resources
    whenever with any amount along with your choice. There are a lot of floor tiles around your base, and also the game
    does not restrict you to one ‘kind’ of each. So stop searching for a working mobile strike hack and also just use our online generator.
    Our Mobile Strike Hack benefits both iOS & Android tools without rooting
    or jailbreaking your device.

  4. says

    big black gay porno his fist gay sex tumblr gay teen sex mature and boy gay porn xvideo gay porn gay massage porn free porn video movies gay mobile porn tube how to have safe gay sex porno gay de maduros surprise gay porno twink fun gay porn porn Double Me, Sc.2 Hairless-Arsed Beaut Gets Double-Fucked & Splattered With Jizz! str8 to gay porn
    gay sex slave boy free gay porn vides uncircumcised gay porn porn hun gay gay chubby porn gay porn pics of ronald weasley nude gay stoner sex totally free porn videos gay male nasty feet verbal porno guy sex video estonian gay porn naked sexy sex gay Gay Room – Gay Creeps – Twink with a Furry Ass – Skylar Mattel & Nick Steele videos porno gay mexicanos

Leave a Reply to mobile strike gold mine Cancel reply

Your email address will not be published. Required fields are marked *