Hijacking a Bundle

by kengilmer

Sometimes in OSGi land bundles you wish would “just work” don’t for some reason.  Sometimes the MANIFEST.MF is just incorrect.  What to do when this happens, and when you don’t have the sources handy?  Decompress the jar, change the manifest, and re-jar it.  That’s what I usually do.  The problem is then I have this funky artifact that is not really stock and is something I need to keep around somewhere.  But today I found a new technique that’s quite nice and doesn’t require mangling artifacts: bundle the bundle in a bundle.

Like most things in OSGi, it’s simple: just create a new bundle, make a manifest as you’d like it to be, embed the source bundle as a jar, and add it to the Export-Classpath header.  Boom, done.   By embedding the bundle it just becomes a jar, and the OSGi bundle classloader should treat it as such.  Now you have a fancy new bundle just how you want it without having to get dirty.

Advertisements