We are currently working on a very interesting project together with basis06 which has Apache Karaf as a target runtime. Coming from the Eclipse space this is really a challenge for the following reason: when you develop OSGi applications within Eclipse you are used to the PDE Tooling (Plug-In Development Environment) together with its concepts like features. You are also used to Equinox with its provisioning platform p2. When you are getting familiar with Karaf you quickly notice that all of this Eclipse stuff is not so good on this platform.
While PDE is great for development it does not help with deployment. Concepts like Eclipse Features simply don’t exist for Apache Karaf. This is the same for p2. Karaf simply can’t do anything with p2 repositories.
So, with these facts in mind, we get to the build. When using PDE you do manifest-first development. This means you manage your dependencies directly in the MANIFEST.MF file. For this reason you probably want to use a build system like Eclipse Tycho which supports this style of development. Sadly, Tycho is tightly coupled to p2 and can only produce artifacts consumable by Eclipse technologies. And here we arrive at the problem: how do we get an Apache Karaf consumable artifact from a Tycho build?
In theory this should not be a problem. Karaf grabs all the bundles it needs from Maven repositories. (I know there are different deployers, but Maven seems the way to go with Karaf.) Basically, Tycho is a Maven plug-in and when you use it, you are doing a Maven build. So, it should not be hard to get Maven consumable artifacts out of it, right? “No, not possible“, was the answer from Igor Fedorenko (a Tycho developer) in the Tycho forum. Well, we simply couldn’t live with this answer. Karaf was set as the target runtime and we wanted to do manifest-first development. For a week and a half, I worked on this topic and tried dozens of different approaches to come to a useful and easy solution. Unfortunately, I couldn’t find any existing solution.
To make a long story short, I think there is at least one solution now ;). I wrote a simple Maven plug-in (strange experience btw.) to build an Apache Karaf Archive (kar) out of a folder containing OSGi bundles. A kar is a packed Maven repository with a Karaf feature. The plug-in’s main task is to mavenize all bundles in a given folder and create a Karaf feature out of it. It also provides facilities to configure the feature like the configuration of start levels, the autostart behaviour, feature dependencies and the creation of config admin configurations. This gives us the opportunity to create a p2 repository with an Eclipse Tycho build and use its plugins folder as input for this Maven plug-in.
The Maven plug-in is called the kar-packager and it should act as a bridge between Tycho and Karaf. It’s hosted on GitHub and available in the Maven Central. To read how to use it in detail, use the README on GitHub. I hope the kar-packager helps you as much as it helps us. As always, feel free to share your thoughts about it in a comment ;).
P.S.: I want to thank Dragan Milic for doing the groundwork on mavenizing OSGi bundles. Your Google Code Project was a great help!