Take the 2-minute tour ×

I have a simple question. I followed this tutorial and created a HelloWorld osgi bundle. How can i install and start this bundle using apache Karaf? How can i refer to the bundle using the osgi:install command?

thank you.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Ok, that is another question, but here goes:

You're pretty much on the right track, I've tested the one in the Karaf developers guide you linked to (the second mvn call). The documentation isn't quite correct, I needed to change two things:

  • The version is off, 2.2.5 does work (on my machine), changing it to 2.2.8 seemed to help.
  • The package name is com.mycompany.package. As package is a keyword, that won't compile, so I've changed it to com.mycompany.bundle.

So my archetype command was:

mvn archetype:generate \
-DarchetypeGroupId=org.apache.karaf.archetypes \
-DarchetypeArtifactId=karaf-bundle-archetype \
-DarchetypeVersion=2.2.8 \
-DgroupId=com.mycompany \
-DartifactId=com.mycompany.bundle \
-Dversion=1.0-SNAPSHOT \

Then I entered the newly made project folder: com.mycompany.bundle:

cd com.mycompany.bundle

And a mvn install:

mvn install

Then there is a jar file in the 'target/' folder, which you can install into the Karaf installation as I said before.

Creating a bundle in Eclipse

  • New -> Plugin Project -> Choose a name -> check the parameters -> you can use a template if you like.

  • Select your project -> Export -> Plugin/Fragment -> Choose a folder

There's your jar file.

share|improve this answer
Thank you man :) That works. I have two more questions: the mvn install command will generate all the classes and the jar and a Manifest.mf in the target folder. What if I want to configure my bundle myself? Where do I have to drop the Manifest.mf file? Can i simply create a META-INF folder and drop it there? The second question: There are many tutorials and how to's of osgi tutorial on the equinox container. Since osgi is a specification it should make nearly no difference when i am using apache karaf instead of equinox right? So i can develop my bundles using Eclipse -> Plug-in Project. ??? –  user1291235 Jul 10 '12 at 11:34
It's a matter of taste: Either you configure your pom.xml file, and configure your pom file to generate the MANIFEST file, or you create your own manifest file (for example in Eclipse). It is a pretty fundamental decision: Do you want to let Maven manage your manifest file, or do you want to do it yourself, using Eclipse? –  Frank Lee Jul 10 '12 at 15:15
I added instructions for Eclipse –  Frank Lee Jul 10 '12 at 15:20
I want to use maven to manage my manifest file(s). When i follow the eclipse way i have no problem to export and import packages. Using Maven, i have no idea how this works. If I have two project bundles (both created with the mvn archtype) and i want set one bundle as a dependency of the other, i have to refer to the package in the pom file... (<import-package> tag) right? How does this work? –  user1291235 Jul 11 '12 at 13:36
You'll have to configure the '<instructions>' part of your pom file. This page explains that: felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html –  Frank Lee Jul 11 '12 at 17:01
show 3 more comments

You can just drop the bundle into the 'deploy' directory, and Karaf just notices and installs it.

share|improve this answer
Thank you for your reply. I now created a osgi bundle using the maven karaf-bundle-archetype: (link: karaf.apache.org/manual/latest-2.2.x/developers-guide/…) But I am still not able to install and run the bundle in Karaf. How can I generate a *jar file out of my bundle so that i can drop it ito the deploy directory... ? –  user1291235 Jul 9 '12 at 18:09
add comment

Your Answer


