Wednesday, September 12, 2012

Disappointed by Jigsaw delay? Java Modularity is here today!

I recently heard that some people are expressing disappointment over the lack of a built-in module system in Java 8, now that Jigsaw is delayed. Some are apparently even looking at technologies other Java because of this. Well, I'd like to point out that There is No Need To Wait! All the modularity that your application needs is already available with OSGi! OSGi pretty much supports everything that Jigsaw was planning to support to allow modularization of applications. And OSGi has more features such as a dynamic lifecycle and a very useful services model. Still OSGi frameworks can be remarkably small. Of the popular implementations Apache Felix is probably the smallest with its implementation in under 500kilobytes. But Eclipse Equinox and our own JBoss OSGi Framework inside AS7 are also very good opensource implementations.

Want to learn how to use OSGi? Like many people I like learning stuff by reading a book. Recently a number of books have been published that provide really good explanations of how to use OSGi, notably OSGi in Action, OSGi in Depth and Kirk Knoernschilds Modular Architecture book, but probably my favorite book is Enterprise OSGi in Action. Besides containing a good description of a number of Enterprise OSGi specs, it also describes really well why certain things are done in OSGi they way they are, which give you a nice and deep understanding of the technology. Additionally it contains some great chapters on how to get your build, test and development environments to work smoothly with OSGi. Enterprise OSGi in Action will be in print later this year, but you can already get it in electronic form from here.

Besides the books, the OSGi Javadoc can be very useful and if you really want to know the details of it all, the OSGi specs are a great resource. Oh, and don't forget to check out the Wikipedia page that shows where you can get implementations of the various OSGi technology.

So in short - no need to wait or turn away from Java if you need Modularity. OSGi is here today and has been used in production by numerous users for many years, just get started by downloading one of the opensource implementations and try it out!

4 comments:

  1. I received this comment from Joonas Koivunen:

    I'd really hope there were more guides for going from web application development with maven (even simple spring webmvc+spring-jdbc) to web application development with maven and osgi (springdm?). From that you could perhaps work your own way to springdm+wicket.

    I've read Java Application Architecture (only theory for OSGi development) and taken a look at (that one Equinox fleet management system example book), OSGi in Action and OSGi in Depth, none of which seem to be of help here (using ackward Ant scripts for example) or being tied up with Eclipse for everything.

    There's just a tad bit too much to understand, for example Eclipse+Equinox is fond of p2 (which I haven't had the time to explore/investigate) yet there seems to be "more standard" OBR (why doesn't eclipse then follow standard?), also why are not OSGi-fied maven repositories any good here?

    Also, apparently there are libraries which cause a lot of pain in OSGi, for example hibernate (which apparently needs something close to Import-Bundle: *, at least Wicket used to require the same for almost same reasons anf for some reason there's PAX-Wicket as well..) however Hibernate (or JPA) and Wicket are vital in actual web application development.

    So, I understand the need for OSGi, some of the principles, but I lack the knowledge of day-to-day OSGi-developing with maven inside eclipse. (I seriously wouldn't want to let go of maven as everyone on our team has finally started to understand it and I really cannot understand why it couldn't be applied here.)

    ReplyDelete
  2. Hi Joonas,
    That's a lot of questions :)

    First let's address the maven question. You can use OSGi with maven in a number of ways. Popular mechanisms are via the maven-bundle-plugin and via Tycho. I'm trying to get more documentation on how to use the various toolchains at the moment, but one such doc page is already available on Maven, see here: http://wiki.osgi.org/wiki/MavenFelixBundlePluginEclipseToolchainI hope that might help.

    Re OBR, while Felix OBR has been available for quite a while, the OSGi Repository Spec is relatively new. It was only released last June (chapter 132 of the R5 Enterprise Spec). Hopefully more repositories will be providing their information in this standard format, which can be generated on the side of the core content, similar to an index. The OSGi Repository RI is freely downloadable at the JBoss OSGi Repository project (ASL2 licensed btw).

    Regarding the migration to a web framework. As OSGi integrates with many web frameworks these will all have their own documentation. I know it works well with Wicket (the Karaf Web Console uses it), JQuery (the Felix Web Console uses it>, Vaadin, Apache Sling and many others. There is no single resource that documents them all, however the book Enterprise OSGi in Action does take the reader through the development of a little website, so this book may help you here too.

    Finally, wrt to the libraries and their use under OSGi. The good news is that more and more libraries are now released with OSGi metadata (manifest headers) so they work both as a plain library as well as an OSGi bundle. I agree that it would be great if there was a good, comprehensive repository of OSGi libraries. Today this doesn't exist yet, but hopefully someone will build one in the not too distant future. The OSGi Repository spec should be a great tool here. From a practical point of view, I'm often able to find libraries that are OSGi-ified in the SpringSource EBR, so that might be of help.

    ReplyDelete
  3. BTW apparently people are having problems leaving comments. If you do, let me know on david.bosschaert at gmail.com. I wonder if this is a general issue with blogger.com...

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete