For years we shipped our desktop applications, ReportMill and SnapCode, as Java Web Start applications, enjoying the built-in auto-update feature it provided. This year we began shipping our apps as native app packages using Javapackager, which makes it easy to generate a exe/app for Windows/MacOS. This has been a huge improvement – we no longer worry what JRE is installed, whether it is broken/missing or whether it will change. The JRE is entirely under our control and hidden from the user. The fact that we use Java at all is now just an “implementation detail”.
The only concern we had when switching was that we still want users to automatically get the latest update without having to re-install the latest version. Fortunately, we found a simple solution: We put the core of the app in a single compact jar file (.pack.gz – like Web Start) on our website and we have an AppLoader main class that does the following:
- Check for new version of jar file on web site
- If found, download and alert user “New Update Available on Relaunch”
- If update from above step is in App-Support directory, move into place
- Create URLClassLoader for latest jar
- Get main class from URLClassLoader, and invoke real app main()
We were able to do this in a single AppLoader.java file in 250 lines of code that only uses JRE classes. To use this in your application, add AppLoader.java to your project, make it the main class and customize the string constants at the top of the file for your AppName, JarName, JarURL and MainClass.
Thanks to Jim Weaver for inspiring us to share this. Hopefully this works well for you, too!
Source code: AppLoader.java