Search code examples
javaosgibundleapache-felix

How to stop a specific Apache Felix bundle using java


I would like to know how to stop a specific bundle in the Apache Felix Web Console running only java code.

For example: I want to be able to retrieve a bundle, let's say by name, and stop it.


Solution

  • From console:

    1. find 'bundle-name' //display bundles , get the id from here.
    2. stop 'id'

    From code:

    1. First get the bundle object using PackageAdmin.getBundles(name)
    2. Call Bundle.stop on that bundle.

    EDIT: To get the PackageAdmin object:

    ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin pa = (ref == null) ? null : (PackageAdmin) context.getService(ref);