Reputation: 4901
I have an application that I need to be a self-contained app, installable, on computers that may not have Java. I'm using javapackager
command to create an EXE that can be sent out to the users, containing all the parts needed. The app, in a simple sense, reads in a file referenced by the first param, does transformations on it, and writes back out next to the source file a result. All of that works when running it as a JAR directly, and also when running it via the built EXE.
The problem is that when triggering the executable, it immediately returns execution to the command prompt, rather than waiting for the process to finish. I don't want to have to poll the output directory to check if the file exists and then give some arbitrary timeout on when to stop looking - I want the app to know that once the console command has completed, the processing is done. At that time I can do logic based on if I find the result file, and alert if it is not found or whatever other logic is right.
Is there a way to tell the javapackager
command to set a wait until Java has died (good or bad) before returning control? Barring that, is there a code snippet/concept that would make the app hold off releasing control back to the terminal until the JVM has died?
Upvotes: 0
Views: 462
Reputation: 4712
I can confirm this behaviour for apps that I've packaged using javapackager
included with Oracle JDK 8, 9 and 10 as well as with snapshots from OpenJDK 13. While the resulting binaries behave "as expected" under macOS and Linux, the Windows binary merely seems to spawn a new process and exits immediately.
Beginning with Java 9 jpackager
invokes jlink
internally, which has an option --strip-native-commands
which basically removes binaries from the embedded JRE. With Java 8 you didn't have this option and executables such as java.exe
are always removed. But my tests show that the JRE is otherwise complete and you should be able to simply include java.exe
manually (better test this thoroughly!).
Therefore I propose the following workaround:
javapackager -deploy -native image
java.exe
from your system-wide JRE installation to {OUTDIR}\runtime\bin
(check if your license covers redistributing java.exe!){OUTDIR}
that calls runtime\bin\java.exe -jar ./app/yourapp.jar
.{OUTDIR}
to your .msi or innosetup installer or .zip file or whatever means of distribution you choose ;-)You can then invoke the bat file instead of the exe. Since it is just a wrapper for java -jar
it will wait until your program finished.
Upvotes: 0