I have a .jar file and a jre folder for that specific .jar, by doing this the user won't have to download Java or if they don't have it, it will still work.
To launch this .jar file I am using a .bat file like seen below.
%~dp0jre\bin\java.exe -jar %~dp0myJar.jar
The %~dp0
part is used to find the path to the jre file and the .jar file.
But the issue is the fact that whenever the .bat file has launched the .jar file, the command prompt is still open. I understand that this is because my program is a "window" app and therefor the command prompt would first close once the .jar program has finished.
To fix this I have tried to modify the .bat file with the following different methods. (not all at once, one at a time)
start %~dp0jre\bin\java.exe -jar %~dp0myJar.jar
start "" "%~dp0jre\bin\java.exe" -jar %~dp0myJar.jar
start %~dp0jre\bin\java.exe -jar %~dp0myJar.jar
exit
start "" "%~dp0jre\bin\java.exe" -jar %~dp0myJar.jar
exit
%~dp0jre\bin\java.exe -jar %~dp0myJar.jar
exit
But... When using these methods, of which seem to work for other people, instead of closing the command prompt completely. It exits the command prompt which launches the .jar file and then opens a blank command prompt. When closing the .jar it then closes the new blank command prompt or if I close the new blank command prompt it also closes the .jar
I am unable to figure out exactly why this is, and why it doesn't just exit the first command prompt which launches the .jar and then that is it.
To try and figure out the issue, I have drawn inspiration from questions like this and many more.
Update
Just tried to run the command straight from a command prompt, instead of using the actual .bat file. But because I am using the method to get the full path of the jre and .jar in the Bat file, I had to instead use the full path. Nevertheless it actually worked this time, by using this method.
my\long\path\jre\bin\java.exe -jar my\long\path\myJar.jar
exit
But when using the same method within the .bat file it doesn't open the blank command prompt, but it never exits the first "original" command prompt.