问题
My Application needs some components (jar files) to be loaded/unloaded dynamically on request. For example, I have abc.jar and xyz.jar and on demand my application should be able to load/unload abc.jar or xyz.jar or replace these jars with different versions of jars. Could you someone please help me with any ideas to load/unload jar files dynamically (i.e. without restarting the server). While reading in net I got few ideas about osgi, but I dont want to go into framework which may make complex. Is there are simple approach to achieve this ? I am using Java, J2EE and Jetty 6 server.
Thanks in advance for your help.
回答1:
Have a look at the seminal paper "Dynamic class loading in the Java virtual machine", by Bracha and Liang. They explain how class loaders work, and how you can use interfaces and class loader to support dynamic changes. It's a worthy read (you should be able to obtain a free PDF by googling the name of the paper) !
回答2:
You Can use Shared Library and Refer the same in your application Server Class/Library path.
And you can change the versions of the jars you place in them whenever you want.
来源:https://stackoverflow.com/questions/16810641/dynamically-load-a-jar