javajarauto-updateserver-application

How can I write a Java application that can update itself at runtime?


I would like to implement a java application (server application) that can download a new version (.jar file) from a given url, and then update itself at runtime.

What is the best way to do this and is it possible?

I guess that the application can download a new .jar file and start it. But how should I do the handover, e.g. know when the new application is started and then exit. Or is there a better way to do this?


Solution

  • The basic structure of a solution is as follows:

    There are a number of ways you could implement this. For example:

    The advantages of the external wrapper approach are:

    The second approach requires two JARs, but has the following advantages:

    The "best" way depends on your specific requirements.

    It should also be noted that:


    If you can find a way to avoid reinventing the wheel, that would be good. See the other answers for suggestions.