Programming Tutorials

Running jar files in background in ssh window

By: Sachi in Linux Tutorials on 2012-07-15  

When you need to run a java application in the background in unix, you can use the screen command. When you run the screen command in your ssh window, even after you close the window, your application will still run. In fact this will work for any application not only java application.

screen -A -m -d -S trackapps java -jar putyourjarfilenamehere.jar

The command "screen -A -m -d -S trackapps java -jar putyourjarfilenamehere.jar" does the following:

  1. "screen" is a command in Linux/Unix systems that allows users to create and manage multiple terminal sessions within a single console window. By using the "screen" command, we can run the specified command in a detached background session, which allows the command to continue running even after we log out or close the terminal window.

  2. "-A" tells screen to adapt the terminal's size to the size of the client's display.

  3. "-m" tells screen to create a new window if there are no existing screens to attach to.

  4. "-d" tells screen to detach the terminal from the current session after it is created.

  5. "-S trackapps" tells screen to create a new session with the name "trackapps".

  6. "java -jar putyourjarfilenamehere.jar" is the actual command that we want to run in the detached screen session. This command runs a Java program (the one specified by the JAR file name) using the "java" executable.

So, in summary, the command "screen -A -m -d -S trackapps java -jar putyourjarfilenamehere.jar" creates a detached screen session named "trackapps" and runs a Java program specified by the JAR file name in that session. This allows the program to continue running in the background even after the user logs out or closes the terminal window.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)