20

I want to know why OSGI framework is used when building java applications. I am searching the web for this but answers look complex to me. Can anyone please explain few points on why we need to adopt osgi.

Am sorry if the question does not suit stackoverflow I appreciate the patience of the readers. Thanks.

Hearen
  • 7,420
  • 4
  • 53
  • 63
javalearner
  • 3,314
  • 7
  • 26
  • 33
  • 1
    Did this help -- > http://stackoverflow.com/questions/1818778/what-is-the-underline-theme-in-osgi – Jayan Dec 06 '11 at 08:30
  • please read this for a very nice descrption:http://blog.springsource.com/2008/05/15/why-should-i-care-about-osgi-anyway/ – Cris Dec 06 '11 at 08:30
  • 2
    possible duplicate of [What does OSGi solve?](http://stackoverflow.com/questions/106222/what-does-osgi-solve) – Martin Dec 06 '11 at 08:38

5 Answers5

17

OSGi provides a modular system with versioning of the modules, and further a bit of life cycle management. It manages dependencies between modules, dynamic/lazy startup/uninstall of modules, lookup/discovery and such.

Part of this will become part of the java language. It enables a lesser complexity than a spaghetti wiring of classes.

Hearen
  • 7,420
  • 4
  • 53
  • 63
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
8

IMHO OSGI on its own requires a a lot of boiler plate code for what it does. However if you use a library like Karaf & iPOJO most of the overhead is hidden and you get most of the benefits.

The main benefit is being able to control which versions are used and proper module isolation. For example you can

  • have the container download the right versions from a maven repository like nexus.
  • use multiple version of the same library and have the modules which need those use the right ones.
  • stop, upgrade and start modules while the application is running.
  • a web console to see the state of all your modules and manage them collectively or individually.
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

For me the best part of OSGi is that it promotes a service-oriented view of your system, which helps decoupling, testing and teamwork.

I don't think it has to be complex, as I tried to demonstrate with my "OSGi for mere mortals" example application [1] and slides [2] (both shameless plugs ;-)

[1] https://github.com/bdelacretaz/OSGi-for-mere-mortals

[2] http://www.slideshare.net/bdelacretaz/osgi-for-mere-mortals

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
1

OSGi is a fast framework because it knows that which service will be loaded into OSGi environment thanks to pre-defined xml file. It reduces runtime cost thanks to lazy state. Service instance is created when they needed. Some bundle's different version can be used by other bundle at the same time. Since each plug-in has it own class loader, any bundle can be stopped, started, installed or uninstalled without stopping Java Virtual Machine.The communication among the bundle is possible by using declarative service or service tracker in OSGi environment via interfaces. Using interface frequently pay the way for reusable code. Although OSGi framework contains quite a few class and interface, powerful projects can be created by using it. Since java runs everywhere, OSGi can also run.

burak isik
  • 395
  • 5
  • 6
1

Go through with this tutorial thoroughly. You might get your answer.

Jwalin Shah
  • 2,451
  • 1
  • 17
  • 22