I have some application, which has ability to update itself. Its downloads the jar file from the net, and then tries to replace used jar to run this application by downloaded one.
But I cannot to do that, because the file is locked by windows, because application is still running.

Does anybody know some workaround of that?
['https://Stackoverflow.com/questions/1748356', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/212822/']
That's a problem **already solved** by OSGi.

The real problem is not to load a new jar version. This could be done with your own classloader that releases the file lock. The real problem is how to [handle instances of different versions of the same class](http://en.wikipedia.org/wiki/Classloader#JAR_hell).

Restart does omit these problem. If you really need different jar versions in one application use OSGi.
Typical way to do this is to write a separate updater which will be invoked by your main program when it sees an update. At this time your main program can start the updater in a new process and exit. You updater can wait for main program to exit, download and copy the updated files and restart your main program