it seems the spec isn't all too clear in that area. For our compiler we
would need a ClassLoader that does not load class that are given as
classpath.... I guess I am not very clear....
java -cp A.jar foo.Bar
we now need the class loader that is allowed to laod classes from
rt.jar, but does not laod classes from A.jar. It seems the spec says for
1.2 that the bootstrap class loader will not do that, but how to get a
hand on it? Giving null as parent seems to result in the system class
loader, which is the one that loads the classes from A.jar... so it is
the wrong one.
Is there any way to do this?
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
I take the huge amount of responses, that there is no safe way for this.
am I at last right when I say that if the parent of a class loader is
null, that this does not mean that the loader has the bootstrap loader
as parent?
and what would that be?
bye Jochen
yes, but is that specified?
bye Jochen
How well do you want it specified? JLS?
That's the best I've found. How likely is it for that to be changed in
a future release, given Sun's stance on backward compatibility?
Cheers,
James
hmm... it says if the parent is null, then the VM built in class loader
will be used. Could it be, that the docs are not very well in that area?
Or is it clear, that the built in class loader is the bootstrap
loader? I think I did read somewhere that in Java 1.1.x the bootstrap
loader did also load classpath elements. And since 1.2 this has been
changed. But I worry not so much because of the Sun VM, I worry more
about if other VMs do that the same way or not
"The bootstrap class loader can delegate the loading of C to some
user-defined class loader L
by passing N to an invocation of a |loadClass| method on L.
The result of the invocation is C. The Java virtual machine then records
that the bootstrap loader
is an initiating loader of C (§5.3.4)
<http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#78621>.
"
Rémi
Jochen Theodorou a écrit :
No, it isn't. There isn't any specified way to do what you want, because the whole notion of a bootstrap class loader is under specified. I'm pretty sure it's legal for a VM to have no bootstrap class loader (i.e. only a system class loader). But in that case you can't make the distinction anyway, so for most scenarios the above should do what you want (unless you absolutely need to prevent loading "user" classes, in which case you should fail to run on a VM that doesn't make a distinction between "user" and "system" classes).
Regards,
Jeroen