Automatically update jar files

I am currently working on desktop software based on java.It has a fairly large code base (over 40 jar files).

I want to provide an automatic update function. Desktop software constantly checks one rear system to see if there are new versions of jar files.

Now the problem: How to replace updated jar files?

+6
java auto-update
source share
4 answers

If you deploy your application using Java Webstart (JNLP), you get this mechanism almost for free ...

From http://mindprod.com/jgloss/javawebstart.html

A key benefit of Java Web Start is automatic updates without having to download the entire program every time.

+3
source share
  • The easiest way is to check for updates every time you start, download updates, and then run the application. I think this is how Java Web Start works (see aioobes answer).

  • More difficult would be to use either netbeans or the eclipse framework for your application. Both of them are quite complex, and you will have to rewrite your application to work with them. This solution supports direct updates.

As far as I know, there is no easy way to update a running application. You can load new versions of a class with a different class loader, but you cannot download old versions while they are still referenced.

+1
source share

You can also serialize your state (store it in memory) and then create a new instance of ClassLoader, pointing to the new .jar files. Then serialize your state again with this new classloader. You have just changed .jars subwords in an executable product.

Note that you do not need to change the class loader for everything just for the part that actually uses .jar files. It can be difficult to figure out which parts. And if you make a mistake, you can get nasty links to errors. So..

.. to make it simple, use WebStart or a preloader that updates .jars and then launches the main application (basically what WebStart does for you).

The reason for your own is that you can use your own format for .jars, encryption, other packaging formats, etc.

0
source share

You can create a small server and a launcher that downloads the latest version, replaces the old one and launches the jar using

Runtime.getRuntime().exec("java yourjar -jar"); 

And you complete the launcher with:

 System.exit(1) 
0
source share

All Articles