Search code examples
osgikaraf

Karaf : dynamic bundle restart


I am developing a composite feature for Karaf (i.e. a feature that includes other features as nested elements). I want to write out configuration files for the nested features and then from the outer scope (i.e. the feature that I am writing), I want to restart the bundles included in the nested features.

  1. How do I query a feature for all of its bundles at runtime from another bundle.

  2. How do I dynamically restart a bundle from another bundle ?


Solution

  • For all two operations you need instance of org.osgi.framework.BundleContext - you can get one in your bundle activator.

    To query features (and their dependent features and their bundles) you need access to Karaf's org.apache.karaf.features.FeaturesService OSGi service - for example using BundleContext's getServiceReference() method.

    To get any bundle (to be able to restart it) you can get one knowing it's ID: BundleContext.getBundle("ID")