I've made a project in Java and I run its .jar file on the Linux terminal but after the successful termination of the program my program ends but the Terminal window did not close. I tried "java.lang.System.exit(0)", but then also the window did not close.
I'm running program by opening terminal and running java -jar filename.jar
I would like the terminal to exit when the Java program exits.
31 Answer
As you already mention, System.exit() just exits the Java program,
not the invoking shell. There are two ways to close the terminal window
after the Java program has stopped:
Either run the Java program and add the exit command in one line:
java -jar filename.jar; exitThis will invoke java -jar filename.jar and when that command returns,
the shell's exit command is executed (effectively closing the terminal
window).
Or replace the current shell with the Java process by issuing
exec java -jar filename.jarThis way the current instance of bash is replaced with an instance ofjava. Hence, when the Java process stops, the terminal window will
close.