views:

60

answers:

3

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. I am finding 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 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?

Thanks.

+2  A: 

The closest thing is OSGi

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

stacker
A: 

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.

Riaan Cornelius
+4  A: 

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

It depends on what you want to do.

Colin Hebert
OSGi is huge and JRebel is only for development since it requires an expensive license (free for OSS projects). Not sure about Hotswap for ant
TheLQ