aspose file tools*
The moose likes Java in General and the fly likes how do make a java application update itself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how do make a java application update itself" Watch "how do make a java application update itself" New topic
Author

how do make a java application update itself

Harry Harding
Greenhorn

Joined: Mar 18, 2010
Posts: 5
I have a java application that is distributed to the public. When the user starts the application it checks my web site for the latest version and if there is a newer version then the app downloads the JARfiles and places them in the appropriate locations. BTW: this is a cross-platform app that runs on Windows, Mac OSX and Linux. All this works so my question is this. Once the download of the new JARs is complete, how to I tell my application to stop itself and then relaunch automatically.

Thanks in advance for any ideas and assistance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Call Runtime.exec() to run a second copy of the application -- which would use the newly-downloaded jars -- and then call System.exit() to stop.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Welcome to JavaRanch, Harry.

The advice on this issue I hear most is switch to Java Web Start. That way users always download the latest version.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Harry Harding
Greenhorn

Joined: Mar 18, 2010
Posts: 5
Paul, Thanks for the tip. I'm going to try this today and let you know how I make out. I have command line parameter I need to pass to the JVM but it looks like Runtime.exec() will allow that. I just need to figure out the syntax. Thanks again.

Rob, Thanks for the tip but I don't know if Java Web Start will help. I don't know enough about it but though my app is downloadable from the web it isn't a web app. It is a desktop app that don't require an internet connection to run. If an internet connection is available it does check for updates but if the connection isn't there it bypasses the check and runs as a local app. Does that fit with the Java Web Start scheme? The app lives on the user's local machine.

Again, thanks to both of you for the feedback.

Harry
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Try starting here. To be honest I haven't used it before so I can't tell you if it caches the versions so you can run them locally.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14268
    
  21

Harry Harding wrote:I don't know enough about it but though my app is downloadable from the web it isn't a web app. It is a desktop app that don't require an internet connection to run. If an internet connection is available it does check for updates but if the connection isn't there it bypasses the check and runs as a local app. Does that fit with the Java Web Start scheme? The app lives on the user's local machine.

Yes, that fits with the Java Web Start scheme. A Java Web Start application is an app that's usually downloaded and installed from the web, but once it's installed it runs just like any other Java program on a user's local machine. Java Web Start provides a mechanism to do exactly that what you describe: check if there's a newer version on the web, if no then run the currently installed version, otherwise download the new version, install it and run that.

Using Java Web Start does not make your application a web app.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

You seem to have the requirement that the application should check every 25 seconds (or some period) to see if there's a new version available, and to update itself on the fly if there is. Is that correct?

Java Web Start doesn't do that. All it does is to check when the application is started for new versions, and download the new version before starting the application if there is one. Generally that's sufficient for most applications, and it works fine if that's what you need.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Rob Prime wrote:Try starting here. To be honest I haven't used it before so I can't tell you if it caches the versions so you can run them locally.

Yes, you can run Web Start applications on your machine without access to the host they came from. I believe there's an option to prevent that from happening, but it's a normal operating mode for Web Start.
Harry Harding
Greenhorn

Joined: Mar 18, 2010
Posts: 5
Thanks all for the advice. Paul, I'm sorry if I was not clear. No I do not have any specific update frequency constraint (25 secs), checking at the start of the app is fine and actually preferred so it sounds like Java Web Start is the answer to my problem. Now all I have to do it learn how to use it. Thanks for the link Rob, I'm going to check this out before I bother you all again.

Also, BTW: Thanks for making a newcomer feel welcome. I think I may have found a new home.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do make a java application update itself