Linux 在后端运行一个java程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9323690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run a java program in backend
提问by java tech
Hi all i want to run a java application as backend process.that is like tomcat server.For that i had developed one application.and made one class as main class and calling from one script file .i.e(startup.sh) file.in startup.sh file i was calling one class.that is MainMethodClass.In main method class i had written my business logic.when i am running this app in linux server from using putty is is working until putty window is not closed.As closed after putty window it is also stopped.but i need to run this app even i closed also.How can i achieve this.
大家好,我想运行一个 java 应用程序作为后端进程。这就像 tomcat 服务器。为此,我开发了一个应用程序。并将一个类作为主类并从一个脚本文件调用 .ie(startup.sh) file.in startup.sh 文件我正在调用一个类,即 MainMethodClass。在主方法类中,我编写了我的业务逻辑。当我在 linux 服务器中使用腻子运行此应用程序时,它一直在工作,直到腻子窗口未关闭。在关闭之后腻子窗口它也停止了。但是即使我关闭了我也需要运行这个应用程序。我怎样才能做到这一点。
采纳答案by cutchin
Nohupwill detach a process you run from your current console and let it continue when you close the terminal. Run something like this.
Nohup会将您从当前控制台运行的进程分离,并在您关闭终端时让它继续运行。运行这样的东西。
nohup java -jar my.jar &
By default it will pipe the output to nohup.out, so if you don't want that you could try:
默认情况下,它会将输出通过管道传输到 nohup.out,因此如果您不希望这样,您可以尝试:
nohup java -jar my.jar > /dev/null &
回答by Manish
This problem is not related to java, its actually something related to the way linux operates.
这个问题与java无关,它实际上与linux的运行方式有关。
You need to do following:
您需要执行以下操作:
nohup <your_application_command> &
Note the "nohup" and "&" at start and end respectively.
注意分别在开始和结束处的“nohup”和“&”。
回答by mikera
You should be able to do something like:
您应该能够执行以下操作:
nohup java -jar MyApplication.jar &
回答by Sandeep Shukla
On a linux machine you can create a service for your jar( executable jar like spring boot )
在 linux 机器上,您可以为您的 jar(可执行 jar,如 spring boot)创建一个服务
# Set the Application as Service
ln -s $APP_BASE/bin/$APP_NAME.jar /etc/init.d/$APP_NAME
echo "Starting the application as service"
service $APP_NAME start