Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with frequent local snapshot bundle deployments on Karaf?

I decided to build an application on top of OSGI and Karaf - I really like this stuff. However, I'm struggling a bit with a daily deployment on my local, development machine. I mean.. I make a change and then I would like to test it on my local Karaf instance. And it can happen like couple times per hour.

The way I'm doing it now is a maven build that creates a JAR bundle and then it's copied into the Karaf's deploy directory. I think that it isn't elegant at all.

I was trying to find a way around (google). I read about Karaf's features but it seems that despite the fact that it is a nice mechanism for deploying whole app, it doesn't solve my problem. As I understand it right, it does not check whether new version of my SNAPSHOT jar appeared in my local maven repo, right?

like image 939
Michal Chudy Avatar asked Jul 16 '14 22:07

Michal Chudy


People also ask

How do you deploy bundles in Karaf?

To add it to the deploy directory run mvn clean package from the root folder of your project (Where the pom. xml resides). This will generate a jar file in the target folder. Drag and drop it to the deploy from there.

What is a bundle in Karaf?

This bundle is simply a Maven POM that shades an existing jar and package into a jar bundle. For instance, to create an OSGi bundle that wraps Apache Commons Lang, you can simply define the following Maven POM: <? xml version="1.0" encoding="UTF-8"?> <

Is Karaf a OSGi?

Apache Karaf is an OSGi based runtime, it is where our Application bundles run. Fuse uses Apache Karaf as its runtime in which bundles run and collaborate to provide business functionality. Karaf is built on Felix and equinox which are OSGi Frameworks.

How does Apache Karaf work?

Remote: Apache Karaf embeds an SSHd server allowing you to use the console remotely. The management layer is also accessible remotely. Security: Apache Karaf provides a complete security framework (based on JAAS), and provides a RBAC (Role-Based Access Control) mechanism for console and JMX access.


1 Answers

The key to make the update mechanism of karaf work is to deploy from maven instead of using the deploy folder. Install you bundle like this:

install -s mvn:groupid/artifactID/version

or

install -s mvn:groupid/artifactID/version/typeOfMavenArtifact

Second one is useful for installing for example war/wab artifacts. Full maven protocol specification can be found here.

Then Karaf knows where the bundle came from. You can also check this using la -u. This makes karaf show the update location which now should be a maven uri. You will not that all karaf bundles have an update location like this.

When you now create a new build of your project using maven it will end up in you local maven repository. Then simply run

update <bundleid>

This makes karaf check the update location (in your case you local maven repo) and reload the bundle from there.

You can even further automate this by using

dev:watch

or for karaf 3+

bundle:watch

This will make karaf check you maven repo for changes in SNAPSHOT bundles it has deployed and automatically redeploy these.

This also works very well together with the remote debugging. Use

export KARAF_DEBUG=true

before starting karaf. It then will listen for a debugger on port 5005.

You can then start a remote debug eclipse session on the same port and nicely debug your application in karaf. This works very well even if you change your bundle using one of the approaches above. So you can debug, find your problem, change the code, build and continue debugging with the changed version.

I also use this frequently when I work at the karaf code base itself as this also works for most of karaf's own bundles.

like image 74
Christian Schneider Avatar answered Sep 28 '22 17:09

Christian Schneider