Classloader Questions [message #90018] |
Thu, 07 June 2007 15:53  |
Eclipse User |
|
|
|
I'm trying to embed Equinox into a J2SE application. This is a legacy
application so I need to be careful what I do and do not change. One
thing I cannot change is a jar I have that is defined on java's
classpath. This jar provides a package called c.a.d.c.boot.
Classes in this package must be visible to the bundles within the
equinox runtime.
So the system classloader has my special package within it. From the
system classloader I spawn a URLClassLoader. From a class within this
URLClassLoader I start the Equinox runtime (via the
EclipseStarter.startup method).
So it occurred to me that this was not all that much different to how
java.* classes are loaded. So I first tried setting the
org.osgi.framework.bootdelegation property to "c.a.d.c.boot.*" (via
EclipseStarter.setInitialProperties before calling startup), this
doesn't seem to have any effect. I've also tried setting the
osgi.parentClassLoader property to "app" and "fwk", still no effect.
Finally , I set org.osgi.framework.system.packages to "c.a.d.c.boot",
this did work, however this seems to be an ill-suited solution as i'm
overwriting everything the JVM is providing (javax.xml.parsers for
example). Every situation ends up with me getting a
NoClassDefFoundError for any import from the c.a.d.c.boot package.
All the properties do seem to be set, per the getprop command on the
equinox console.
So my question is, how can a bundle refer to a class in the package
c.a.d.c.boot without making this package a bundle itself? There seems
to be some discussion out there regarding extension bundles, but I
thought this was overkill as it seems to me that this should be somewhat
solvable through the provided property mechanism.
What am I missing?
Thanks for your help.
-brett
|
|
|
|
|
|
|
Re: Classloader Questions -- solved. [message #91045 is a reply to message #90093] |
Thu, 21 June 2007 13:35   |
Eclipse User |
|
|
|
One follow up to this. If I have a 3rd party jar (foo.jar) which provides org.db.foo, that I want
to use within my bundles, but for argument's sake, I'm too lazy to wrap it as a bundle itself, and
too lazy create a system.bundle frag to bridge it. I would have thought I could set the
bootdelegation property to be org.db.foo.* and add add foo.jar to the jvm's classpath and all would
work properly, but this doesn't seem to work at all.
I half expected this to only work with classes in the SystemClassLoader, but the jars on the
classpath I believe are loaded into the system classloader.
That being said, I did add javax.* to the bootdelegation property and that seems to work just fine.
But setting the bootdelegation property to "javax.* org.db.foo.*" worked for swing, but not the
classes in org.db.foo.
What am I missing regarding this property?
Thanks.
-Brett
Danail Nachev wrote:
>
> If you set the bootdelegation property, then you don't need to set
> anything (only the class loader hierarchy correctly). When you set the
> bootdelegation, you don't need to import the package in the bundles
> which are using it.
>
|
|
|
Re: Classloader Questions -- solved. [message #91127 is a reply to message #91045] |
Fri, 22 June 2007 13:51  |
Eclipse User |
|
|
|
The parent classloader for bundle classloaders in equinox is the boot
classloader by default (look in eclipse help for the
osgi.parentClassLoader configuration property). That is different that
the "system class loader". The system classloader is actually a
hierarchy of three classloaders
Application -> Extension -> Boot
When you place jars on the jvm's classpath (by using -classpath etc) the
jar ends up on the Application classloader not the boot classloader.
The bootdelegation property delegates to the parent classloader of the
bundle classloader which is boot by default. Setting
osgi.parentClassloader=app should do the trick.
HTH
Tom.
|
|
|
Powered by
FUDForum. Page generated in 0.03674 seconds