Dynamically load a jar [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-11 19:18:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!