开发者

Swapping a running jar at runtime

I am building an update system in which I need to be able to replace a referenced jar of a running application jar at runtime. However, I am running into file locking issues on Windows when trying to perform file utility functions on the jar such as 'setLastModified'.

After some googling I found this snippet...

What I found in my research is that the standard ClassLoader implementation never closes a jar file once it has been opened. It also only loads resources from the jar file as needed. So at any particular time, there may be Classes in the jar file that have not been loade开发者_开发问答d into memory. Obviously, if you delete the jar file out from under the ClassLoader, and it tries to find a resource in the missing file, you're going to get an IOException at the very least.

Does anyone have any references to information on doing this, or working around this issue?

Thanks.


There is a lot of solutions for classes/lib hot-swapping :

  • Hotswap for ant
  • JRebel
  • OSGi

It depends on what you want to do.


The closest thing is OSGi

Please have a look at the 'See also' section of the mentioned artice for concrete products.


I don't know of any good way to deal with this. Creating a custom classloader might be an option, although I don't like that idea..

We worked around it by running an updater from a separate jar before launching the main application. This works well enough, but obviously, you can only update the jar when the application is launched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜