63

I've just started hearing the term OSGi being used (while reading tutorials on common Java EE containers such as GlassFish and Spring), however I have been unable to find a simple, straight-forward, easy-to-understand explanation of what OSGi is that an enterprise novice such as myself would understand.

Can someone provide such a dummy-proof explanation? Maybe with some examples or even code excerpts?

Thanks!

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Zac
  • 761
  • 2
  • 8
  • 6

2 Answers2

76

Simply said, OSGi is a dynamic module system for Java. It defines means to install, uninstall, update, start and stop modules. Those modules are called bundles, but are, in their simplest form, actually Java jar files with a special Manifest. Modules can be installed, uninstalled etc without stopping or restarting the Java VM.

An OSGi framework manages the described lifecycle of and dependencies between the bundles in a secure way. A bundle needs to state which Java packages it exports and which it imports. The import and export statements can be annotated with version information, so that you even can have more than one version of the same package in the same Java VM.

The OSGi Alliance is the organization that specifies the OSGi framework and many accompanying services, e.g. for managing configuration data, device access, etc.

This is just a very basic overview. OSGi is much more. Please have a look at https://www.osgi.org/resources/architecture/ (an introduction to OSGi's architecture) and https://www.osgi.org/resources/where-to-start/ (a lot of links and further readings recommended by the OSGi Alliance).

Update 07/2021
As of 2021 the OSGi Alliance moved all resources and work to the Eclipse Foundation. It continuous its work in the newly established OSGi Working Group.

Andreas Kraft
  • 3,754
  • 1
  • 30
  • 39
  • WoW !! This is the best answer to the question. Thanks – Walker Dec 22 '11 at 15:53
  • 1
    Simplest explanation I saw for OSGI, should be on the front page of osgi.org so people can get in 2 mins what usually takes a day. Its frustrating when projects have pages and pages of marketing and PDFs on a official site, while to understand we just need a nice summary like this. Thanks for this ! – xask Aug 24 '16 at 12:06
34

At the expense of some down votes ;-), I'd like to answer this in my own words (so that I can get corrected on my understanding).

We build applications as a set of modules, each module functionally cohesive with-in itself and loosely coupled with other modules. This has many advantages as you might already know. Overtime time, the unit of modularity has improved from functions to classes to packages to a unit of deployment (like jar in Java and assembly in .Net). But all of this is only during development time, once the application (which is a set of modules) is deployed, the server still see's it as one giant monolithic application i.e. the logical boundaries are not preserved during runtime. OSGi makes these boundaries explicit during development as well as runtime apart from other benefits outlined here

I suggest this excellent free book to get you started OSGi in Practice

If you work on Java platform, also check this presentation: Why Have The OSGi Specifications Been Based On Java™ Technology?

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • Thanks to both akr and Pangea for taking the time to clear this up. I think I'm starting to "get it". It sounds like OSGi is a powerful framework for making JARs PnP - yes?!? One last thing - can someone provide me with some concrete examples of bundles ("services") and what they might do? Thanks to everyone! – Zac Jan 03 '11 at 13:42
  • @Zac You may find some information about OSGi, how to use bundles and how to create or consume services for example in [this tutorial](http://www.javaworld.com/javaworld/jw-03-2008/jw-03-osgi1.html?page=1). It is quite good in my opinion. – Piotr Jan 04 '11 at 17:01
  • Is it used in today's products or it is mostly a standard that is being developed and in a rolling out period ? I saw the term associated with main application servers (eg. Weblogic) - are they making use of it or is still in a testing period ? – Victor Jan 15 '20 at 14:22