Linux – Run Jar in Background on Linux

javalinux

I have a jar that runs forever (infinite loop with socket listening thread) and need it to run in the background at all times. An example would be: "java -jar test.jar" How do I do this? Thanks in advance!

Best Answer

several ways:

  1. appending & at the back. However, using this, the program will still be terminated if you closed the terminal that started the program.

  2. Start a screen session, and start the program inside it; you can detach the screen session and close the terminal. Later on, you can attach to the session again and found yourself back on the console as if you've been there all along. However, you will need to start a screen session before running the program, and if you forgot to do that, you can't do anything about it.

  3. Use disown job control from your shell. This will detach the task from your tty and your program won't be terminated when the tty is closed. However, I don't think there's any way to reattach a disowned job.