I recently found myself in the situation where I needed to provide an easy way for a client to install a set of OSGi bundles and their dependencies. Karaf Features allow you to name a collection of bundles and other Karaf Features for easy installation using a single command. If you’ve never heard of a Karaf Feature, refer to the Karaf documentation for a good tutorial. By combining a feature descriptor with the PAX URL Wrap Protocol and Maven Protocol, you can provide your users with a simple deployment mechanism to support provisioning existing bundles as well as creating bundles from non-OSGi ready JARs at deployment time. While the Spring EBR and ServiceMix both maintain a collection of non-OSGi JARs that have been converted to OSGi bundles, sometimes you need to convert a JAR that is not in one of these repositories to an OSGi bundle, or your users cannot access one of these repositories.
In this situation, you can either create the bundle from the JAR and distribute this bundle to your end users or you can couple PAX URL, Karaf Features, and Maven together to provide a small and easy to distribute installation descriptor. In my case, I need a small and self-contained Zip package for distribution. Creating bundles from the needed third-party JARs and distributing them in the Zip package would unnecessarily bloat the distribution package. This blog post discusses how to combine the tools mentioned above to script the creation of OSGi bundles during installation of a Karaf Feature.
Continue reading →