equinox-dev-bounces-j9T/66MeVpFAfugRpC6u6w@public.gmane.org wrote on 2008/06/02
08:58:36 AM:
> [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-j9T/66MeVpFAfugRpC6u6w@public.gmane.org
>
> Please respond to Equinox development mailing list <equinox-dev-j9T/66MeVpFAfugRpC6u6w@public.gmane.org>
>
> I'm trying to call Package.getPackages() in some code in an OSGi
> bundle. This calls into getPackages on the classloader, where
I'm
> observing that:
>
> 1. The call is not overridden in the Equinox classloader, so
the
> 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
are
> 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
that
> ClassLoader instance". Which seems to suggest that both
packages of
> 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?
>
> Regards,
> Jan
> _______________________________________________
> equinox-dev mailing list
> equinox-dev-j9T/66MeVpFAfugRpC6u6w@public.gmane.org
>
https://dev.eclipse.org/mailman/listinfo/equinox-dev
--