Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to add a self-update feature to a Java Swing application?

Tags:

java

swing

I'm trying to figure out a way to add a self-update feature to a Java/Swing application I'm working on.

Basically I've got a bunch of jar files with extra functionality to be re-deployed to the installed users when they change. Nothing complicated, just check if a new version has been released, download them over HTTP, and then optionally offer to restart the app to the user.

I had a look at webstart, and it could work. But this particular app does some funky stuff with classloading and GC memory settings that don't look like they are supported via webstart, or will at least complicate matters. (It's a tweaked build of JMeter)

I also went down the road of adding in this plugin handler http://swing-fx.blogspot.com/2008/06/add-auto-update-and-plugins-to-your.html, but it is very alpha, and tries to do too much with the usual bugs you get with alpha stuff.

like image 545
madlep Avatar asked Oct 16 '08 05:10

madlep


People also ask

Is Java Swing still updated?

Oracle will continue developing Swing and AWT in Java SE 8 and Java SE 11 (18.9 LTS). This means they will be supported by Oracle through at least 2026.

What is replacing Java Swing?

Hint: Oracle has developed JavaFX to replace both Swing and AWT. Since Java SE 7, update 6 it is bundled with Java SE. "JavaFX is a set of graphics and media packages that enables developers to (...) deploy rich client applications that operate consistently across diverse platforms" [1].

Can Java Swing be used in web applications?

Webswing is a web server that allows you to run any Java Swing application inside your web browser, using only pure HTML5.


2 Answers

I did the exact same thing. But that was long back so there are probably better tools today.

What I found out I needed was a loader. The loader main program did not have the app jars in classpath. It first downloaded an update if required and then created a custom classloader with the app jars in class path and invoked the main method of the application main class. It is not very complicated. IIRC I needed to do this because the jars could not be overwritten in windows if they were already in classpath.

Hope this helps.

like image 156
Miserable Variable Avatar answered Nov 02 '22 22:11

Miserable Variable


we had a swing app 6 years ago that had self-update. like you suggested,

1)it downloaded the latest jars over http,
2) copied them to a folder.
3) since the swing app is launched using a .BAT file, after user said YES, we would shut down the swing app and look for any files in the update folder. if yes, launch another .BAT file to copy the NEW JARs to the required directory.
4) then re launch the swing app.

like image 24
anjanb Avatar answered Nov 02 '22 23:11

anjanb