javaswingself-updating

how to write Java Swing self updater (non Java Web Start solution)?


  1. check server for a directory containing updates.
  2. download the jars to current application directory.
  3. notify user to restart app.

My concern is with overwriting the old files while the java application is running.

for example myapp.jar and other library jar has been updated and needs to be replaced by downloading the new versions into the current application directory and overwriting it in the process. Is there a way to achieve this? Will it allow overwriting?


Solution

  • You can't count on being able to overwrite jar files. It will probably work on Linux, but definitely not on Windows.

    One way to solve this is to download the jars to a temporary location, and then when you start (before the JVM starts) move the temp jars to the app download location and then start. Note: you will want to verify the contents of the jars somehow after download to make sure they're not corrupt. An md5sum will work.