Jeremy G
Jeremy G

Reputation: 568

Get InputStream of bundle already installed in OSGi runtime?

I am trying to create a backup file of a bundle that is installed in the runtime, so that I can uninstall it and then possibly reinstall from the backup if I want. Does anybody know how to get a handle on the location of the bundle file that is already installed in the runtime? I would like to do this in a way that will work regardless of OSGi container (specifically, I want it to work in Equinox and Felix). Ideally this would be information gained from the Bundle object (or from information from an object acquired from the Bundle object).

Edit: In a nutshell, I am getting every bundle installed (bundleContext.getBundles) and from that attempting to determine file paths of the bundles.

Upvotes: 0

Views: 905

Answers (2)

BJ Hargrave
BJ Hargrave

Reputation: 9384

You can't do this. The OSGi spec does not provide any way to get the input stream for an installed bundle. This is mostly because the OSGi does not require that bundles come in the form of a JAR nor that they be stored in any archive format. For example, an OSGi framework could store the entries of a bundle in a database and then look up requested classes and resources from that database. So you see there is no guarantee the bundles exist in JAR form after installation.

Upvotes: 1

Christian Schneider
Christian Schneider

Reputation: 19606

Use bundle.getLocation(). It will return the location the bundle was installed from (if available). There is no guarantee that you can load the bundle jar from there but depending on how you originally installed the bundle this works.

Upvotes: 0

Related Questions