0

I am trying to build a simple auto updater for my application. I am currently checking the local application version against my remote version. If there is a newer version I want to start my updater.jar - which basically downloads and replaces the old application.

My problem is that I cannot seem to get the updater.jar to start if there is a new version.

The code I am currently using is:

Runtime runtime = Runtime.getRuntime();
try {
    Process proc = runtime.exec("java -jar updater.jar");
} catch (IOException ex) {
    Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);

The application exits but updater.jar is never launched..

Any ideas?

Leigh
  • 28,765
  • 10
  • 55
  • 103
Alosyius
  • 8,771
  • 26
  • 76
  • 120

3 Answers3

0

Your child process is likely exiting when your parent process exits.

When you launch a process you should usually:

  1. consume stdout/stderr from the child process. If you don't do this your child process can block waiting for its output to be consumed. You should consume in separate threads. See this answer for more details
  2. use Process.waitFor() to capture the exit code from the child process

It looks to me like you want to spawn the updater, let it perform a download and then exit your parent process. Anything more complex would likely be platform dependent (e.g. spawning a background process and disowning it)

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • Yea im kind of stuck how would code to launch updater.jar look like? Tried bunch of different stuff cant get anything to work – Alosyius Jul 17 '13 at 13:43
  • AFAICT, you can't have child process living after the parent has died in Java. Updating Java software automatically can be a major PITA (even big software products like [IntelliJ IDEA](http://jetbrains.com/idea) had -- if not still having -- a hard time relaunching after successful updates; anyway, I bet they came up with something platform-specific for these purposes). – BorisOkunskiy Jul 17 '13 at 13:59
0

Maybe the path to updater.jar should be specified in the java -jar command.

kgautron
  • 7,915
  • 9
  • 39
  • 60
0

You better use the URLClassLoader since jre1.2

see How to load a jar file at runtime

Community
  • 1
  • 1
Grim
  • 1,938
  • 10
  • 56
  • 123