Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one make a Java application self-updating? [duplicate]

I am developing an application that will be rolled out to Windows computers. Because my clients have very little computer knowledge the installation and update need to be as easy as possible. I want the installation to be the only manual step, updates should be done automatically.

Installation will be done via Installshield or more likely by one of its open source clones. The installer will install these components:

  • a Java runtime (Oracle JRE) as a kind of portable app (that means by simply copying the contained files and not using the provided installer)
  • Apache Commons Daemon to install my application as a Windows service
  • the application itself in the shape of several JARs created with Spring Boot

When one of those components changes I want to update them automatically and as silently as possible. The application will be able to determine if updates are available on the web and download them.

What options do I have to achieve this ? Java Webstart is in my eyes not a good solution - for example it does not enable me to update the runtime. Providing an update installer will need user interaction and perhaps even administrative rights so it wil not run silently.

The proposed link below does not fit my problem because I use a daemon which needs to be updated during runtime and neither of the given solutions in the linked post supports that.

like image 640
Marged Avatar asked Oct 31 '22 03:10

Marged


1 Answers

May I suggest for you to reconsider Java Web Start? Even Wikipedia knows that

Important Web Start features include the ability to automatically download and install a JRE in the case where the user does not have Java installed, and for programmers to specify which JRE version a given program needs in order to execute.

If you still don't want to use Web Start then here is totally silent solution which I use on Windows boxes. Let's say here is restart.bat:

 cd \myApp
 echo Killing myApp
 pskill.exe myApp
 TIMEOUT 5

 del /q Release
 copy \\mainCIcomputer\Build Release

 TIMEOUT 5
 cd Release
 start myApp.exe

All what you have to do is to start separate process and then run restart.bat from it. You can use any technique to determine when to reload your app (for example http/ftp request to get latest version number and restart if it is different from existing). Don't forget - this process should be separated to not be killed with you main myApp. It could be start from another batch, or, in my case I use IronPython:

from System.Diagnostics import Process
p = Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = False
p.StartInfo.FileName = 'restart.bat'
p.Start()
p.WaitForExit()
like image 170
Alex Avatar answered Nov 14 '22 03:11

Alex