[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[equinox-dev] Question regarding class loader and getPackages()

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.
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 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