Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] org.osgi.framework.Bundle from java.lang.Class

Hi Matthew,

Sounds like a job for Package Admin:

/**
 * Returns the bundle from which the specified class is loaded. The class
 * loader of the returned bundle must have been used to load the specified
 * class. If the class was not loaded by a bundle class loader then
 * <code>null</code> is returned.
 * ...
 */
 public Bundle getBundle(Class clazz);


But what does "outside the framework" mean? If you mean hat you're outside
an OSGi runtime, and therefore don't have access to the PackageAdmin
service, then you shouldn't need to care about the x-internal either.

Regards,
Neil


> I would like to know, from outside the framework, which bundle a
> particular class belongs to. I can use the following code snippet
>
>                 ClassLoader loader = clazz.getClassLoader();
>                 BaseClassLoader baseClassLoader = (BaseClassLoader)loader;
>                 Bundle bundle =
> baseClassLoader.getClasspathManager().getBaseData().getBundle();
>
> but I get "Discouraged access ..." warnings because the
> org.eclipse.osgi.baseadaptor package is x-internal. Is there another way
> to do it?
>
> Thanks in advance.
>
> Matthew Webster
> AOSD Project
> Java Technology Centre, MP146
> IBM Hursley Park, Winchester,  SO21 2JN, England
> Telephone: +44 196 2816139 (external) 246139 (internal)
> Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> http://w3.hursley.ibm.com/~websterm/_______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/equinox-dev
>




Back to the top