在运行时交换正在运行的jar [英] Swapping a running jar at runtime

查看:149
本文介绍了在运行时交换正在运行的jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个更新系统,我需要能够在运行时替换正在运行的应用程序jar的引用jar。但是,当我尝试在jar上执行文件实用程序功能时,我遇到了Windows上的文件锁定问题,例如'setLastModified'。

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...


我在研究中发现的是
标准的ClassLoader
实现从不打开一个jar
文件。它还
只根据需要从jar文件
加载资源。所以在任何特定时间,
可能在jar文件
中有未加载到内存中的类。
显然,如果从ClassLoader下删除jar文件
,并且
尝试在
缺失文件中查找资源,那么你将得到一个
IOException至少。

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 loaded 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?

谢谢。

推荐答案

有很多类的解决方案/ lib hot-swapping:

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

  • Hotswap for ant
  • JRebel
  • OSGi

这取决于你想做什么。

这篇关于在运行时交换正在运行的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆