OSGi Diaries – A short series

I’m going to be spending some time over the next couple of weeks learning about OSGi – there is an application at work that we want to try and make more modular. In particular, we’d like to be able to share the back tier with more front end clients. The more conventional modularisation techniques, such as EJBs, have been tried and didn’t work fairly well. Simply creating more deployments is prohibitive, due to hardward And before someone asks “why not just stick a web service on it and share that way” – some of the front end clients will be those web services. To cut a long story short, one of the options we want to check out is OSGi.

The only problem is that there isn’t much in the way written up on the web about writing OSGi components – at least not without invoking magic tools (e.g. Maven plugins) that don’t work on any version of any tool developed six months later. Which is odd, because OSGi, as a spec, doesn’t look that hard to write too. So, I thought I’d write up a series describing the initial investigative spikes, starting as close to the metal as possible and working up.

Two servlets, talking to a shared service.
Two servlets, talking to a shared service.

The application I’m going to build for my spike is a very simple concept: two servlets, talking to a shared service. The shared service keeps track of a counter; one servlet gets the status of the count, and the other increments it. We’ll start with the entire app in one single normal WAR, and evolve it in progressed stages into three distinct OSGi bundles – with the Counter Bundle being shared.

For the spike, I’ll be working with Glassfish V3. The examples use Maven, but I’m deliberately going to avoid the various OSGi plugins; there’s nothing special about OSGi bundles – they’re just normal JAR files with special entries in the MANIFEST.MF file. If you want to try the examples yourself (I will be posting them), but don’t want to use Maven, it should be simple enough to use Ant instead.

My main reference will be the OSGi specs, but where I get reference from other sources, I’ll be sure to cite them.

The first post in the series (which should be up tomorrow) will cover what it takes to get an OSGi-enabled web application up, as a stepping stone to the end goal. As a starter, though, feel free to check out the initial starting point.


Author: Robert Watkins

My name is Robert Watkins. I am a software developer and have been for over 18 years now. I currently work for people, but my opinions here are in no way endorsed by them (which is cool; their opinions aren’t endorsed by me either). My main professional interests are in Java development, using Agile methods, with a historical focus on building web based applications. I’m also a Mac-fan and love my iPhone, which I’m currently learning how to code for. I live and work in Brisbane, Australia, but I grew up in the Northern Territory, and still find Brisbane too cold (after 16 years here). I’m married, with two children and one cat. My politics are socialist in tendency, my religious affiliation is atheist (aka “none of the above”), my attitude is condescending and my moral standing is lying down.

3 thoughts on “OSGi Diaries – A short series”

  1. These days, I’m using Maven, at least at work and I don’t do enough personal coding to bother looking elsewhere. Sigil sounds interesting – using OSGi runtime data about dependencies would probably solve the worst of the dependency nightmares you get with Maven (which are mostly caused by the over-eager transitive dependencies).

    For the purposes of these examples, I intend to keep very tool free – anyone should be able to follow even if they use a tool besides Maven. No plugin magic for now. Eventually, I’ll expand outwards to tool support – I will see if I can fit in an Ant example with Sigil then.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s