Hi,

Just wondering, is it a good idea for some class to get its bundle
BundleContext from its own classloader, like this:

BundleContext ctx = ((BundleReference)
ThisClass.class.getClassLoader()).getBundle().getBundleContext();

It seems to me that the only limitation is that getClassLoader() may
require additional permissions.

The reason I want to do it this way is that I have a lot of bundles
without activator which want to get BundleContext from time to time. Of
course, adding an activator that will remember BundleContext is a simple
thing, but that's a pretty boilerplate code which I need to add to a
number of bundles (about 20 or so).

Probably, Declarative Services or Blueprint Container can inject those,
but my project currently does not use them and seems like adding them
immediately is not very possible.

What do you think? Is there a better way to get Bundle/BundleContext
without writing explicit activators?

-- 
WBR,
Ivan S. Dubrov



_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to