1

I have code intended to automatically update my Jar application. I want to run a Jar file from my application with parameters to tell the new version to do some post-update cleanup and then exit. I can launch it using Desktop.open() but I cannot pass any parameters this way. I can also launch the java executable using ProcessBuilder however on Windows I would want to use javaw and on other platforms I will want to use java. Is there a way to do this without having to worry about the current platform?

Community
  • 1
  • 1
Fr33dan
  • 4,227
  • 3
  • 35
  • 62
  • Wouldn't `Runtime.getRuntime().exec("javaw -jar file.jar");` do the job? – Selim Jan 23 '14 at 22:41
  • @Selim It as the same problem that I will need to use `javaw` on Windows and `java` on other platforms. – Fr33dan Jan 23 '14 at 22:42
  • You could always always do System.getenv() or some such to obtain data that would tell you (with a little analysis) what OS you were on. (Never have figured out why the Java archies are so resistant to having a straight-forward way to obtain such info.) – Hot Licks Jan 24 '14 at 00:32
  • @HotLicks Indeed and that is what I have done. But it just feels like bad form to be checking the OS to do a task that should be platform independent. – Fr33dan Jan 24 '14 at 01:23

1 Answers1

0

I'd consider approaching this from a different direction: Have a wrapper tool which creates a ClassLoader, loads the jar using that, and executes it. When a new version becomes available, tell the wrapper to do this again using the new instance of the jar, and then shut down. This will let the previous ClassLoader go out of scope and let it and the classes it loaded from the previous jarfile be garbage collected.

keshlam
  • 7,931
  • 2
  • 19
  • 33
  • It is a clever idea but in order for this to work I would have to distribute two jar files to my user initially. The wrapper and the current version of the main application. – Fr33dan Jan 24 '14 at 16:05