From Eclipse Tycho to Apache Karaf: the easy way!

From Eclipse Tycho to Apache Karaf: the easy way!

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!


  • Christian Schneider
    Posted at 10:25 pm, August 22, 2012

    You should at least also give the pom first way a try. From my experience it is much easier to just use the maven bundle plugin and give it some hints than creating a full manifest. See this for some examples:

  • Stefan Weber
    Posted at 8:51 am, August 24, 2012

    We had a similar problem. But unfortunately we are using some bundle that replace existing ones (eclipse link moxy instead of native jaxb from the jre). These bundles needs to be installed as system bundles because the need to be started earlier than the rest of the application (otherwise some karaf bundles fail to start). Thus it is not sufficient to create a kar archive and put that into karaf.
    Additionally if you want to have your own karaf branding you need to install it as a library bundle. All these thinks are not possible which kar achives (as far as i know).

    So we created a maven build containing ant and groovy scripts to create the application build containing all of our bundle, some additional 3rd party bundles and the karaf runtime. Of cause as a multiplatform build.
    Not perfect und hell yes not that maintainable but it works 🙂

    But nonetheless good work and at least you know that you’re not the only one having this problem.
    Maybe there will be a maven plugin in the future to do all those thinks mentioned.

    Best Regards

  • Aaron Digulla
    Posted at 6:01 pm, September 6, 2012

    You should try Maven Tools 4 Eclipse (mt4e):

    In a nutshell, it can convert OSGi bundles into Maven artifacts.

  • Aaron Digulla
    Posted at 4:40 pm, September 19, 2012

    No, mt4e doesn’t need Eclipse. It’s a standalone JAR and a pure command line application. So what you did was just reinvent the wheel.

Post a Comment