The java -jar command runs in the background in Linux (nohup, &)

java -jar x.jar When executing the jar package in this way, the command window must be always open, and the program that closes the window must also be closed.

java -jar x.jar & Add & at the end, the test result is as follows GIF:
Insert image description here
It cannot stop at all, and the program also closes after closing the window.

solution:

[root@centos56 www]# nohup java -Dfile.encoding=utf-8 -jar /opt/bcdSystem/jeecg-cloud-nacos-2.4.5.jar > /opt/bcdSystem/logs/nacosLog.txt 2>&1 &
[1] 10475

Command details:

nohup : Run the command without hanging up and continue running the corresponding process after exiting the account.
Insert image description here
The above is that nohup redirects the output of the command to the specified "nacosLog.txt" file in the current directory, that is, the output content is not printed on the screen, but is output to the "nacosLog.txt" file.

Not specifying a file name will create nohup.out in the current directory. If the nohup.out file in the current directory is not writable, the output is redirected to the $HOME/nohup.out file. If no file can be created or opened for appending, the command specified by the Command parameter cannot be called.

2>&1 : The preceding 2 and 1 have the following meanings:

0 Standard input (usually the keyboard)
1 Standard output (usually the display screen, the user terminal console)
2 Standard error (error information output)
Is this command equivalent to redirecting standard error to standard output? Here & is equivalent to standard error and standard output, that is, outputting standard error and standard output to the specified "nacosLog.txt" file at the same time.

Output the error log information of the running jar to the log.file file, and then (>&1) continues to output to the standard output (the & added in front is to allow the system to recognize it as the standard output). The last & means running in the background. .

& : Let the job run in the background.

Guess you like

Origin blog.csdn.net/weixin_54514751/article/details/126280231