1

I have written a java program with jar file. The java program is to update status of linux server so it need to keep running, but the linux server is in data center, so I need to remote to server to open the program. I use ssh to login linux server. Use command of "java -jar file.jar" to run the program.

However, the java program of the linux server will close if I close the terminal in my computer. Since I cannot keep opening my computer, I wanna know how to open the java programming without holding my computer terminal.

Allen
  • 11
  • 1

4 Answers4

3

you need to use nohup to keep the program running after you log out.:

server:~name$> nohup java -jar file.jar &

this will keep your program running

Dima
  • 8,520
  • 4
  • 26
  • 56
2

Two ways

One

nohup java -jar file.jar &

Another

java -jar file.jar &

In both cases your process will go in background however the process will terminate in the second approach when shell terminates in second case.

Puru--
  • 1,101
  • 11
  • 27
  • Here is the response: "nohup: ignoring input and appending output to `nohup.out'" – Allen Mar 24 '14 at 09:14
  • That is perfectly fine your stdout will be redirected to nohup.out. Point is did your process go into background, or it did not? – Puru-- Mar 24 '14 at 17:56
0

If this program is intended to be running on all your machines for monitoring purposes, you should be running it as a service from your server's init system (systemd for most systems these days). You can use the Java Service Wrapper or jsvc or write your own init script.

chrylis -cautiouslyoptimistic-
  • 72,004
  • 20
  • 117
  • 147
0

Another solution apart from the proposed one:

screen -d -m java -jar your.jar

You will then have a detached screen with your java command in it. List with screen -l, reattach with screen -D -RR <screenid_obtained_via_screen_-ls>

fge
  • 114,841
  • 28
  • 237
  • 319