views:

102

answers:

3

They is kind of an open-ended question.

Anyways, here at work we've got a few very large Java EE software projects. Here's a quick description of our projects:

  • They are divided into a few dozen Maven projects.
  • Some of those projects change on every release; others don't change for months.
  • All are Maven/Spring-driven.

Is OSGi the right way to go?

We would like to:

  • Decrease coupling between projects.
  • Manage inter-project dependencies better.
  • Use both old and new versions of projects, depending in the build (or better yet, at runtime).

Have you guys found something better than OSGi to manage this type of thing? Or have you stayed away from it? Has Spring-DM made life easier?

+1  A: 

I would recommend not coding directly to OSGi's API, as it's fairly obtuse and there's not a lot of good examples. I'd recommend SpringSource as a general platform, the Eclipse Rich Client Platform (for clients), or GlassFish v3 (for servers).

samkass
I get the impression that Spring-DM has removed a lot of need to code directly against OSGi API's, although I haven't used it personally. Thoughts?
The Alchemist
+2  A: 

Yes OSGi is the best solution, at least in the Java world.

  • Decreasing coupling can be achieved with OSGi Services. These are like decentralised dependency injection -- publishers and consumers of functionality need have no knowledge of each other, they both only depend on an API (i.e. an interface).

  • OSGi allows you to manage dependencies using imports and exports of packages. The visibility of packages is strictly limited, i.e. only packages that are explicitly exported from one module and imported into another are visible to the importer. So you can always see exactly what dependencies exist between modules.

  • OSGi exports are versioned, and imports use version ranges. OSGi will only allow an import to resolve if an export of a matching version can be found. Therefore it is possible to cleanly evolve versions of both implementation modules and API modules, with the version number used to signal backwards (in)compatibility. Multiple versions of the same module can be loaded and used in the same application.

Spring-DM is a technology that builds on top of OSGi and makes the programming of OSGi Services easier, so it is definitely worth looking into. Alternatives to Spring-DM include "Declarative Services" (DS) and iPOJO.

Neil Bartlett
Thanks much, Neil. Have you used "Declarative Services" or iPOJO? iPOJO seems to be Felix-specific, or at least used mostly with Felix.
The Alchemist
I mostly use Declarative Services. iPOJO is not Felix specific... the code for it is developed as a sub-project of Felix at Apache, but it will run happily on Equinox or Knopflerfish. In fact, almost all of the Felix sub-projects will run on Equinox and the Equinox ones will run on Felix. That's part of what being modular is all about ;-)
Neil Bartlett
+1  A: 

Service creation can be done in the following ways

  • Bundle-Activator using servicetracker (very error-prone)

  • Declarative Services

  • Spring-DM

  • iPojo

  • OSGI Blueprint (standardization of Spring-DM)

  • Guice Peaberry http://code.google.com/p/peaberry/

When using maven also have a look at maven-bundle-plugin, which makes making your project OSGi ready a snap.

Pax Construct is also worth checking out.

Leen Toelen

related questions