1

Is it possible to update a jar file/library used by a Swing application at runtime ?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
feruz
  • 53
  • 10
  • I have written a launcher that automatically updates itself, the game it goes with, and a server interface for the game. If you want to see some code, let me know. – nrubin29 Mar 16 '14 at 21:55
  • yes please, it would be great! – feruz Mar 18 '14 at 05:29
  • See Core, Core Server, and Core Launcher on my GitHub page: https://github.com/nrubin29/. If this is helpful, let me know and I'll post it as an answer. – nrubin29 Mar 18 '14 at 14:08

3 Answers3

3

For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start.

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or locale, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

JWS works on Windows, OS X & *nix.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • See [JNLP API Examples: Using the `DownloadService` Service](http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/examples.html#DownloadService). – Andrew Thompson Mar 18 '14 at 09:07
  • thank you for example. It looks like a solution. But I have never done JWS for my Swing application. Could you please help me out? How can one use JWS with ready application, Let's say we have hello world swing application [HelloWorld.java](http://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java) – feruz Mar 18 '14 at 09:55
  • *"Could you please help me out?"* Sure. Follow the link in the answer. On that page, I have collected some of the best links about JWS deployment. – Andrew Thompson Mar 18 '14 at 10:33
1

To change the CLASSPATH inside a Java program you need to play with ClassLoaders, a very detailed explanation can be found in this previous question: How do you change the CLASSPATH within Java?

Community
  • 1
  • 1
Roberto
  • 8,586
  • 3
  • 42
  • 53
1

It is doable, updating the jar file is simple but you need to update loaded classes in runtime as well. You need to work with classloaders to do so. You can have some more info here for instance:http://zeroturnaround.com/rebellabs/reloading-objects-classes-classloaders/

Hakan Serce
  • 11,198
  • 3
  • 29
  • 48
  • does it mean I have to create new instance of GUI? How do I replace library if it is already locked to the GUI, meaning, I have tried to replace file from gui but it is failing to rename/remove/update library. – feruz Mar 16 '14 at 09:15