问题描述
我需要在服务器中运行一个 java jar 以便在两个应用程序之间进行通信.我已经编写了两个 shell 脚本来运行它,但是一旦我启动了该脚本,我就无法关闭/终止该进程.如果我按 + 或关闭控制台,服务器将关闭.谁能帮我修改这个脚本以作为普通服务器运行?
I need to run a java jar in server in order to communicate between two applications. I have written two shell scripts to run it, but once I start up that script I can't shut down / terminate the process. If I press + or close the console, the server will shut down. Could anyone help me how to modify this script to run as a normal server?
#!/bin/sh
java -jar /web/server.jar
echo $!
#> startupApp.pid
推荐答案
你可以试试这个:
#!/bin/sh
nohup java -jar /web/server.jar &
&符号,切换程序在后台运行.
The & symbol, switches the program to run in the background.
即使在您注销后,nohup 实用程序也会使作为参数传递的命令在后台运行.
The nohup utility makes the command passed as an argument run in the background even after you log out.
这篇关于在服务器上运行 java jar 文件作为后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!