equinox-dev-bounces@xxxxxxxxxxx wrote on 2008/06/02
> [image removed] >
> [equinox-dev] Question regarding class loader and getPackages() >
> Jan Stette >
> to: >
> Equinox development mailing list >
> 2008/06/02 08:59 AM >
> Sent by: >
> equinox-dev-bounces@xxxxxxxxxxx >
> Please respond to Equinox development mailing list <equinox-dev@xxxxxxxxxxx> >
> I'm trying to call Package.getPackages() in some code in an OSGi
> bundle. This calls into getPackages on the classloader, where
> observing that:
> 1. The call is not overridden in the Equinox classloader, so
> default implementation in java.lang.ClassLoader is used. Hence,
> only the bundle's own packages, and the system packages are returned.
I don't think imported packages should be listed since
they are imported from other bundles.
> 2. Only packages from which at least one class has been loaded
> returned. So, if a class hasn't been loaded from a given package,
> it won't be included in the returned list.
> I haven't found anything in the OSGi or Java language specs that
> specify this, but I expected all packages that the bundle
> classloader can see to be returned, something aking to the java doc
> description of Package.getPackages(): "Get all the packages
> currently known for the caller's ClassLoader instance. Those
The packages "currently known" are those
for which at least one successful class load has occurred. There is no
reliable or specified way for a class loader to "know" all the
classes which it can successfully load.
> packages correspond to classes loaded via or accessible by name to
> ClassLoader instance". Which seems to suggest that both
> classes that haven't been loaded yet, and packages imported by the
> bundle class loader should be listed.
> I realise that the Package Admin service is an alternative for this,
> but I'm surprised if these details can't be accessed through the
> class loader...
> Could anyone shed some light on this, please?
> equinox-dev mailing list