Moonlit
Moonlit

Reputation: 5419

how to install and run osgi bundle in apache karaf

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.

Upvotes: 7

Views: 21771

Answers (3)

jwebuser
jwebuser

Reputation: 103

Frank's answer helped me quite fast:
I created a bundle with this archetype:


    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 \
    -Dpackage=com.mycompany.bundle
Then i did a mvn eclipse:eclipse and mvn install. After copying the generated jar into the deploy directory of my running JBoss Fuse server it printed "Starting the bundle". :-)

Upvotes: 2

Frank Lee
Frank Lee

Reputation: 2748

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 \
-Dpackage=com.mycompany.bundle

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.

Upvotes: 6

Frank Lee
Frank Lee

Reputation: 2748

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

Upvotes: 6

Related Questions