How to start With OSGi

Hello
Here I will tell you about OSGi(Open Service Gateway intitative) platform for java. This is beneficial framework for embedded system to function in java. Mostly people function in embedded c, so here i've got also solution for those folks using JNI that i'll explain in this next article regarding OSGi.

Steps to make OSGi with Basic Hello globe programme. Here i'll use Equinox and Apache felix Library for OSGi. comply with these step
Firstly Download Eclipse for your Operating Syatem.

1. Make Your libarary
i) Download the Equinox through http: //download. eclipse. org/equinox/
ii) Go to make workbench for eclipse
iii) GO through  Window--> Preferences--> java-->buid path-->user libraries
iv) Select New and allow User library name "Equinox". Now click on Add external jars, Select every one of the jar files which are inside plugins folder of Equinox and click on OK.
so here you've made your Library.
2. Come up with a simple hello World program.
i) Make new project "plug-in project". Compose project name "helloWorld".
ii) Select target to run being a OSGi framework as Equinox and make certain you have checked for the ACTIVATOR inside next window. then click "Next".
iii) Select HELLO OSGi Bundle and finish it.
and activator under src is present and progarm of Activator is compared to that

package simple;
import org. osgi. platform. BundleActivator;
import org. osgi. platform. BundleContext;

public class Activator implements BundleActivator {
    private HttpServiceTracker serviceTracker;

    /*
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext context) throws Exception {
        System.out.println("Hello World!!");
       
    }
   
    /*private HttpServiceTracker serviceTracker;
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext context) throws Exception {
        System.out.println("Goodbye World!!");
       
    }

}

There are Start and Stop Method. When we will give start command with particular bundle then it'll start and if we give stop command then it'll stop that particular bundle.

3) Run
i) Go to run configuration and choose OSGi framework. Select new and allow name "OSGi" and  click on Run.
you will notice in console like that

osgi> ss
"Framework can be launched. "


id    State Bundle
0    ACTIVE org. over shadow. osgi_3. 9. 1. v20130814-1242
1    ACTIVE org. over shadow. equinox. simpleconfigurator_1. 0. 400. v20130327-2119
2    ACTIVE com. ibm. icu_50. 1. 1. v201304230130
3    ACTIVE helloWorld_1. 0. 0. qualifier
Hello World!!
osgi>

    ss is command showing how many bundle is Active, Resolved.
    now Give the Stop Command "stop 3"
    it will show that adheres to that
Goodbye World!!
osgi>

So this can be the simple Hello World Programme with OSGi using Equinox.

                                                                                                    Anshul Madan
                                                                            CASCADEMIC Solutions Pvt. Ltd.

Comments

  1. Thanks Anshul for bringing up this interesting article on OSGi Start-up information. Could you also elaborate with more details of OSGi applications, in your future articles.

    Abdullah khan

    ReplyDelete

Post a Comment

Popular posts from this blog

TOUCH SENSING SOFTWARE

LoRa and its suitability for IoT

How to make servlet using OSGi