> Possible solution: I plan to have a custom classloader (derived from
> java.lang.ClassLoader) that gets hooked in to my threads using
[quoted text clipped - 10 lines]
> resource-related methods do I need to override so that resources are
> searched for first in my classloader then in parent classloaders?
Looks like loadClass, getResource, and getResourceAsStream would be good
enough. You should be aware that this non-standard order can cause
problems unless usage of the classes to be loaded by your out-of-order
loader is sufficiently isolated. That is, it's problematic if:
ClassLoader1 is the system classloader.
ClassLoader2 has ClassLoader1 as a parent.
However, ClassLoader2 checks for ClassX elsewhere before delegating to
ClassLoader1.
ClassLoader1 loads ClassA.
ClassLoader2 loads ClassB.
ClassA has a method foo(ClassX).
ClassB wants to call ClassA's foo(ClassX) method.
However, as long as usage of ClassX is isolated across that boundary,
you can avoid the problem. Just make sure you understand and document
this limitation with regard to the class library that is loaded out-of-
order.
> 2. I was thinking of using a URLClassLoader as a helper to my
> classloader, invoking its method(s) from my custom classloader's
[quoted text clipped - 4 lines]
> Does this approach make sense? Have you seen anything like this done
> before?
No, I wouldn't do it like that. I'd set up a URLClassLoader as a
"friend" classloader, and write a new sort of composition classloader
that delegates to its friend, and then to its parent only if the friend
can't help... kinda like your average adolescent. So there'd be three
ClassLoaders in all, but the actual ClassLoader that you write would
only exist to delegate to others. Does that make sense to you?

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
gary_shank@stercomm.com - 14 Nov 2005 20:41 GMT
All I want to do is programatically override the classloader (without
specifying -Djava.system.class.loader) so that it calls my classloader if it
can't find a particular class. No matter what I've tried - it doesn't work.
For instance, Thread.setContextClassLoader doesn't do it. I can explicitly
create a class using my classloader with Class c = Class.forName("Foo", true,
loader), but as soon as I try doing Foo foo = (Foo)c.newInstance() - I get
NoClassDefFoundError yet my classloader's loadClass nor findClass methods
were called. I thought, from all the various articles I've read, that I
should be able to hook my classloader into this elaborate chain so that I can
try to resolve anything that the parents can't. Basically, I'm trying to do
the class loading of jar's within a jar. I'm aware of the One-Jar stuff but
I'm trying to do this without any 3rd party code.