Hello,
I have an URLClassLoader named "MyClassLoader" set up with some jars on it. If I try
MyClassLoader.loadClass("MyClass");
it works.
If I try
Thread.currentThread().setContextClassLoader(MyClassLoader);
Thread.currentThread().getContextClassLoader().loadClass("MyClass");
it also works.
But If I try
Thread.currentThread().setContextClassLoader(MyClassLoader);
Class.forName("MyClass");
it throws a ClassNotFoundException
.
Of course, Class.forName
here is just an example; trying to use MyClass
throws the exception just as well.
All this probably means I don't understand how setContextClassLoader
works. Could anyone clarify this to me and help me understand it - and what should I do to make my code work? Thank you.