Monday, April 27, 2009

OSGi matters! - Scala libraries as OSGi bundles

No question: Scala is great! At least that’s what every Java developer would think. But just like Java Scala is lacking a higher-level module system. As there is currently no support for modularity built into the JVM, it is up to a framework to provide such. There is a well established and mature module framework around: OSGi. It lets us define modules called bundles which are just usual JARs with some additional metadata. But what are the benefits of going for OSGi bundles instead of plain JARs?
First, a bundle declares its public API and its dependencies. Hence we can really hide our implementations which gives us a great deal of flexibility.
Second, bundles, exported packages (public API) and imported packages (dependencies) use version numbers. This allows for installing the same bundle in different versions at the same time. No more JAR hell!
Third, OSGi is a dynamic module system: Bundles can be installed, updated and uninstalled anytime. This enables real hot deployment.
There are a lot of further benefits, e.g. a service-oriented architecture which enables loose coupling, different standard services for common tasks like logging, http, etc., but it should already be obvious, that OSGi makes a lot of sense.
As OSGi purely relies on Java, it is easy and straightforward to enable OSGi for Scala: Just provide the Scala libraries (scala-lang.jar, scala-swing.jar, etc.) as OSGi bundles with suitable bundle manifests. The “official” Scala libraries are not (yet) delivered as OSGi bundles. There is an Eclipse plug-in which is part of the Scala IDE for Eclipse which basically is an OSGi bundle, but it is an all-in-one bundle (assembles scala-*.jar) and - very important - contains a rather special bundle manifest that is not-so-good for general purpose.
Therefore I have created the scala-lang-osgi project which provides OSGi bundles for each Scala library. No changes are made to the libraries themselves but only the necessary manifest headers are added to the MANIFEST.MF file. All OSGi-fied Scala libraries are deployed to the scala-tools.org Maven repository with group id org.scala-lang-osgi using the same artifact id and version as the non-OSGi Scala libraries (e.g. scala-library, scala-swing, etc.). Of course there is also a snapshot repository.
These OSGi-fied Scala libraries are already used in projects that rely on OSGi and Scala, e.g. ScalaModules and BindForge. They will also be used for OSGi-fying Lift. If you also go for OSGi on Scala, please give it a try and give me your feedback.

7 comments:

Simon C. said...

Very cool. As a Scala fan and OSGi user I look forward to see your solution; because either you do like the Eclipse plugin did by putting scala-library into a big bundle or you end up with a more modular approach and different bundles, but applications will depend on many of them (because of Scala.Predef depending on many parts of the scala lib).

Anyway I really think Scala need to support OSGi or Jigsaw (and I'd like OSGi and Jigsaw to play nice ; imo Jigsaw should reuse most of OSGi but provide some language level elements). I have followed your progress on Scala Modules and I hope you succeed with this new project!

Neil Bartlett said...

Just to add something that Heiko didn't explicitly say but I think it important: this does NOT affect you in any way if you are not using or interested in using OSGi.

There is no dependency on the OSGi APIs, there is only a little extra metadata in the MANIFEST.MF files in the JARs. Non-OSGi applications will simply ignore that metadata.

happygiraffe said...

Is it worth attempting to get the OSGI manifest info into Scala 2.8? It won't affect anything else, and it would be much better to rely on it as part of the official build.

Heiko Seeberger said...

That's exactly what I am dreaming of. Well, not every night, but sometimes ;-)

I talked to Miles and Josh and maybe we will attempt to convince the EPFL guys to add this little piece of metadata to the "official" libraries. But there are still some details to figure out ...

jerry said...

Thanks for the effort.
I am making use of OSGIfied scala in my project and now looking to use Casbah driver. Looking for Casbah OSGI bundles now. Do let me know if you are aware of where i can get them.

Greenwood Jonny said...



obat alami menghilangkan sipilis
obat alami menyembuhkan penyakit sipilis
obat alami penyembuh sipilis
apa obat alami penyakit sipilis
obat alami penyakit sipilis
obat penyakit sipilis secara alami
obat sipilis buatan sendiri
obat sipilis buat wanita
obat sipilis bagi wanita
obat sipilis beli di apotik
obat buat sipilis

Dedi Abdullah said...

kutil kelamin di liang vagina
Yang jual obat kutil kelamin di daerah bngkinang ada tidak?
jual obat untuk kutil kelamin di kota semarang
jual obat kutil penis daerah sorong
jual obat kutil kelamin di solo
gatal berlebihan dimuara Vagina
jual obat penghilang kondiloma
antibiotik kutil kaki
apa nama obat antibiotik untuk kutil kemaluan wanita
jenis obat antibiotik yang dikonsumsi penderita kutil kelamin