6

Is there any way to update the system class loader at runtime? After I've dynamically loaded a jar file, is there anything I can do to add the classes/packages loaded from this jar into my system class loader?

The reason I'm trying to do this is that while I've had some success through just passing around my newly created ClassLoader in my own code, I'm having trouble with a third party library (apache-WSIF) that doesn't seem to be working with the passed in ClassLoader.

Fozefy
  • 665
  • 2
  • 7
  • 23
  • Possible duplicates: http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime and http://stackoverflow.com/questions/194698/how-to-load-a-jar-file-at-runtime – paradigmatic Jul 07 '11 at 22:25
  • I don't think you can add any things to the system class loader at runtime. The reasons are explained in the answers to the questions linked by paradicmatic. – Paŭlo Ebermann Jul 08 '11 at 01:22

1 Answers1

7

I've been able to achieve what I was attempting to do using the following:

Thread.currentThread().setContextClassLoader(myClassLoader);

As discussed in the top answer here: How do you change the CLASSPATH within Java?

Basically, before calling into the WSIF library all I need to do is make sure I've set my custom classLoader as the contextClassLoader on the current thread.

Community
  • 1
  • 1
Fozefy
  • 665
  • 2
  • 7
  • 23