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/']
I think the correct thing to do here is to **restart** the application. Event if you could update the jar at *runtime*, all sort of errors might occur after because of class versions, different classes, different implementations, etc.
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