Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy easily to Karaf Osgi container with maven project

I'm developing an OSGI bundle for parsing a PDF file using PDFBox library. I use maven to build the project and Karaf as the OSGI container. The PDFBox library is OSGI compatible so I thought this would be easy. But I just can't get the deployment model right.

In a traditional web app I would build a single WAR-file containing all the dependencies and put it in a Servlet container and it would get deployed. On the other hand the only way I've figured how to install an osgi bundle is by doing it by hand. I have to create an installation instruction file that lists all the dependencies that have to be manually downloaded and copied to the Karaf deploy folder, and be sure to do it in the right order. I feel like I'm back in the stone ages.

There has got to be an easier way, right? I still use maven to declare dependencies but I just have to use the provided scope. It would be great if those dependencies could be automatically installed.

I'm using the maven-bundle-plugin to generate a bundle from my application. It does generate an OBR repository(repository.xml) and I tried installing my bundle using obr karaf plugin but it still doesn't help with dependencies.

like image 956
palto Avatar asked Mar 07 '14 15:03

palto


1 Answers

There are different possibilities for provisioning bundles. I prefer to install a bundle using Maven via the Karaf console such as:

install mvn:org.apache.pdfbox/pdfbox/1.8.4

If you don't want to install every bundle one by one, you could use so called features as described here. A feature lists all needed bundles:

<feature name='my-project' version='1.0.0'>
    <feature version='2.4.0'>camel-spring</feature>
    <bundle start-level='80' start='false'>mvn:com.mycompany.myproject/myproject-dao</bundle>    
    <bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-service</bundle>
    <bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-camel-routing</bundle>
</feature> 

You add a feature via Karaf console:

features:addUrl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.0.0-m2/xml/features
features:install nmr

Instead of the mvn handler, you could also use the file handler:

features:addUrl file:base/features/features.xml
like image 80
Peter Keller Avatar answered Sep 24 '22 13:09

Peter Keller