Osgi – the first program

March 1 2007No Commented

Categorized Under: Java, Osgi, Software Engineer

Here is the simple Osgi application with Equinox framework and I use Maven as build tool. The structure of this project is described in follow:

ows-osgi-tutorial
--src
|--main
|--java (contains all java source files)
|--resources
|--META-INF
|--MANIFEST.MF

The manifest file has content:

Manifest-Version: 1.0
Bundle-Name: Helloworld
Bundle-SymbolicName: Helloworld
Bundle-Version: 1.0.0
Bundle-Description: Hello world sample bundle
Bundle-Vendor: NextSS company
Bundle-Activator: ows.osgi.sample.Activator
Bundle-Category: Tutorial
Import-Package: org.osgi.framework

The POM file has content:

 
<?xml version="1.0" encoding="UTF-8"?>
&lt;project xmlns="<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0"</a>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:schemaLocation="<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>
                    <a href="http://maven.apache.org/maven-v4_0_0.xsd">http://maven.apache.org/maven-v4_0_0.xsd"</a>&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;ows&lt;/groupId&gt;
&lt;artifactId&gt;ows-osgi-tutorial&lt;/artifactId&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse&lt;/groupId&gt;
&lt;artifactId&gt;osgi&lt;/artifactId&gt;
&lt;version&gt;3.2.1.R32x_v20060919&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;archive&gt;
&lt;!--Maven generate the default manifest file, these statements in --&gt;
&lt;!--plugin section will force Maven use your own manifest file--&gt;
&lt;manifestFile&gt;src/main/resources/META-INF/MANIFEST.MF&lt;/manifestFile&gt;
&lt;/archive&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

And we write the simple Activator class for Helloworld bundle:

 
package ows.osgi.sample.Activator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
public class Activator implements BundleActivator {
public void start(BundleContext context) {
  System.out.println("Start helloworld service");
}
 
public void stop(BundleContext context) {
  System.out.println("Stop hello world service");
}
}

Open the console and type mvn package, you will have the jar file ows-osgi-tutorial-0.0.1.jar and it is done. You can deploy this bundle to any osgi-compliant framework as felix or equinox. I have tested on equinox by following commands:

- Start equinox: follow equinox guideline.
- Install the bundle: %osgi-console%> install <path of ows-osgi-tutorial-0.0.1.jar >
- Check whether the bundle install: %osgi-console%> ss (you will get the bundle of installed bundle by this command too).
- Start bundle: %osgi-console%>start <bundle id>

It is simple, right? It's time for you to create the more complicated tutorial, just modify the manifest file and Activator class. The build system is ready for use without any change.

Subscribe

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • BarraPunto
  • Bitacoras.com
  • blinkbits
  • BlinkList
  • blogmarks
  • BlogMemes
  • BlogMemes Cn
  • BlogMemes Fr
  • BlogMemes Jp
  • BlogMemes Sp
  • Blogosphere News
  • Blogsvine
  • blogtercimlap
  • Book.mark.hu
  • Bumpzee
  • co.mments
  • connotea
  • De.lirio.us
  • Design Float
  • DotNetKicks
  • DZone
  • eKudos
  • email
  • Fark
  • Faves
  • feedmelinks
  • Fleck
  • Furl
  • GeenRedactie
  • Global Grind
  • Gwar
  • Haohao
  • HealthRanker
  • Hemidemi
  • Identi.ca
  • IndianPad
  • Internetmedia
  • kick.ie
  • Kirtsy
  • laaik.it
  • Leonaut
  • LinkaGoGo
  • LinkArena
  • LinkedIn
  • Linkter
  • Live
  • Ma.gnolia
  • Meneame
  • MisterWong
  • MisterWong.DE
  • muti
  • MyShare
  • MySpace
  • N4G
  • Netvibes
  • Netvouz
  • NewsVine
  • NuJIJ
  • Ping.fm
  • PlugIM
  • Pownce
  • ppnow
  • Print
  • Propeller
  • Ratimarks
  • Rec6
  • Reddit
  • SalesMarks
  • Scoopeo
  • scuttle
  • Segnalo
  • Shadows
  • Simpy
  • Slashdot
  • Smarking
  • Socialogs
  • SphereIt
  • Spurl
  • StumbleUpon
  • Symbaloo
  • Taggly
  • TailRank
  • Technorati
  • ThisNext
  • Tipd
  • Tumblr
  • TwitThis
  • Upnews
  • Webnews.de
  • Webride
  • Wikio
  • Wikio FR
  • Wikio IT
  • Wists
  • Wykop
  • Xerpi
  • Yahoo! Buzz
  • YahooMyWeb
  • Yigg

Leave a Reply