在服务器上将Java jar文件作为后台进程运行 [英] Run java jar file on a server as background process

查看:476
本文介绍了在服务器上将Java jar文件作为后台进程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在服务器中运行Java jar以便在两个应用程序之间进行通信.我已经编写了两个Shell脚本来运行它,但是一旦启动该脚本,就无法关闭/终止该进程.如果按 ctrl + C 或关闭控制台,服务器将关闭.谁能帮助我如何修改此脚本以作为普通服务器运行?

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 ctrl+C 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文件作为后台进程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆