Easy installation of bundles in Apache Karaf

Easy installation of bundles in Apache Karaf


Apache Karaf provides many convenient ways for bundles installation:

  •     Use of the install command in Karaf's command prompt
  •     Copying of bundles to the deploy directory
  •     Use of Apache Karaf features

From these three alternatives Karaf features seems to be the most advantageus. It allows the installation and uninstallation of many bundles in one go. No bundles will be installed, if there is a problem even with a single one. This helps you keep a clean container and spot errors easier. It supports mvn, http and file protocols making the installation of bundles from different locations easier. Last, but not least, it can also install non-OSGi jars (jars without an OGSi manifest), with the aid of the wrap protocol.

In a previous post about Spring-JDBC in an OSGi environment the usage of Karaf features with the Maven protocol was presented. A features.xml file pointing to bundles in Maven repositories was created. The features.xml file was hosted by a Maven project, making it possible to add a features Maven URL in Karaf.

However bundles are not always available in Maven repositories. Sometimes all you have is a zip file with all necessary jars or some HTTP URLs. This is especially true in Aniketos project, where there are contributions from many partners, using both Maven and Eclipse RCP for development and there is also some legacy code involved. In these cases Apache Karaf are still useful.

This is an example of a features.xml file that points to jar files in the local file system:

<features>
  <feature name='greeter_server' version='1.0'>
    <bundle>file:///c:/Tools/Aniketos/bundles/common/org.osgi.compendium-4.2.0.jar</bundle>
    <bundle>file:///c:/Tools/Aniketos/bundles/greeter_sample/cxf-dosgi-ri-singlebundle-distribution-1.3.1.jar</bundle>
    <bundle>file:///c:/Tools/Aniketos/bundles/greeter_sample/cxf-dosgi-ri-samples-greeter-interface-1.3.1.jar</bundle>
    <bundle>file:///c:/Tools/Aniketos/bundles/greeter_sample/cxf-dosgi-ri-samples-greeter-client-1.3.1.jar</bundle>
  </feature>
</features>

These can easily be installed in one go:

karaf@root> features:addURl file:///path/to/features.xml
karaf@root> features:install greeter_server

If you modify one of the jar files and you want to re-install, then you can use:

karaf@root> features:uninstall greeter_server
karaf@root> features:install greeter_server

If you want to remove or add a jar file in the features.xml file, then you can refresh the URL:

karaf@root> features:refreshURl file:///path/to/features.xml
karaf@root> features:install greeter_server

In another post I am going to explain how the wrap protocol supported by Karaf can help in certain situations.

ANIKETOS newsletter

Stay informed on our latest news!

Login

Only for users who has an user and a password sent by the administrator.