Modular Java with OSGi and Spring

I was lucky enough to be asked to preform a technical review of “Modular Java: Creating Flexible Applications with OSGi and Spring“.  It’s Craig Walls‘ next book and it’s being published by the Pragmatic Programmers.

Craig does a great job of making the case for modular Java development with OSGi.  He covers why we need to start thinking about more than just how we design our methods / classes and focus more on how we design reusable Java modules.

First, Craig makes the case for modular design.  Then he talks about how OSGi enables us to write modular Java applications.  He covers both the Apache Felix and Eclipse Equinox OSGi containers.  Next you are writing and deploying a HelloWorld OSGi service.  And that’s all done in the first two chapters!

Craig spends the rest of the book covering modular Java and OSGi concepts through the development of an example project, Dude Where’s my JAR.  You also throughly learn an invaluable tool for OSGi development, Pax Construct. You learn about and writing and deploying OSGi bundles, then writing, deploying and consuming OSGi services.

Once you think you know everything about OSGi, and might be thinking that it’s a bit complicated, Craig brings in the Spring Framework.  He covers Spring Dynamic Modules for OSGi (Spring-DM) which is used to eliminate all of the OSGi-specific code in the example application.  You refactor the app away from depending on the OSGi API.  You change the services to POJOs and OSGi services then inject them into other beans.

My favorite thing about this book was that I didn’t have to read 1000 pages to understand the concepts and get up and running.  Like all the Pragmatic Programmer books, you are educated, and up and running in a few 100 pages.  Read this book if you want to quickly get up-to-speed on OSGi and Spring Dynamic Modules.