views:

63

answers:

3

I am currently working on desktop software based on java.It's quite a big code base (more than 40 jar files).

I wish to provide an automatic update functionality. The desktop software constantly checks one back end system to see if there are new versions of the jar files available.

The problem now is: How to replace the updated jar files?

+3  A: 

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

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

The key benefit for Java Web Start is automatic update without having to download the entire program every time.

aioobe
Based on experience, I would recommend that the jars have the version in their filename. This results in different versions having different URL's - having the same URL for different versions occasionally resulted in a jar not being properly updated in the local cache.
Thorbjørn Ravn Andersen
@Thorbjørn: apart from that reason, version numbers in jars are generally a good idea: make each file name unique.
Joachim Sauer
thanks for suggestion, I will consider it.
@Joachim, as I said, the URL's will be different as the file names are different.
Thorbjørn Ravn Andersen
@Thorbjørn: I know and I agree. I just wanted to re-inforce that version numbers in jar files are a great idea. For the reason you posted *and* for other reasons as well.
Joachim Sauer
I tried, It gave a lot of problem related to JVM. very hard to troubleshoot. For example - http://stackoverflow.com/questions/3584966/java-control-panelany suggestion on this?
A: 
  • Easiest would be to check for updates on each startup, download the updates and then launch your application. I think this is the way that Java Web Start works (see aioobes answer).

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

As far as I am aware there is no easy way to update a running application. It is possible to load new versions of a class with a different classloader, but not possible to unload old versions while they are still referenced.

josefx
A: 

You can also serialize down your state (keep it in memory) and then create a new ClassLoader instance pointing to the new .jar files. Then serialize up your state again using this new classloader. You have just changed the underlaying .jars within a executing product.

Please note that you do not need to change the classloader for everything only for the part that is actually using the .jar files. This can be tricky to conclude what parts that are. And you might get nasty linking errors if done wrongly. So..

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

A reason for rolling your own, is that you can use your own format for the .jars, encryption, other packing formats etc.

UnixShadow