Oh, sorry for my poor presentation skill, I mean that now I have create an URLClassLoader A, and its URL[] is B, now I need to load and unload all the jars in B dynamically. But I don't know how to do it.
-
1You are going to need to be more specific about your question. It is hard to understand. Do you use Maven to gather .jar resources? – djangofan Nov 06 '12 at 02:49
-
I had changed my description , I don't know if I made myself understood clearly to you. Thanks for your attention. – user1801857 Nov 06 '12 at 07:05
1 Answers
Classloaders might be immutable, which means that the main system classloader cannot be changed by your code. This does not mean you can't create your own 2nd classloader on top of the main classloader BUT it does mean that you probably cannot unload classes from the system classloader without restarting the JVM. I suspect your question is a duplicate of this one: How should I load Jars dynamically at runtime? . That suggests that OSGi might be the answer: http://www.osgi.org/Technology/WhatIsOSGi . Here is a link to a HelloWorld example.
If you need a simpler method to unload or add classes, you might investigate methods of restarting the JVM with a different classpath. If you run your app in one JVM and you have a second JVM in the background that your app talks to , your main app might be able to restart the background JVM with a different classpath. Just an idea. I am not an expert in this area and so there are probably more ingenious ways of doing it.
-
Thanks for your attention, I will think over your suggestion seriously. Thank you very much. – user1801857 Nov 07 '12 at 05:49