Tuesday, July 23, 2013

Running a Java app as a daemon on Linux

There are many ways to run a Java app on a Linux device. The problem is that normally when you log out, this app will stop executing. This is a problem when you want the execution to out-live the session.


A command that can solve this issue is nohup. This command will ensure that the execution does not stop when you logout. Also it will not block the terminal.

This is used like this:

nohup java -jar MyJar.jar &

Note :

What will not work is adding an ampersand behind the command. This would be like this:

java -jar MyJar.jar &

The reason for this is that even though this would not block the terminal, it is still tied to the current session. So once the session ends, it will stop executing.

No comments: