Run a java program in backend

我与影子孤独终老i 提交于 2020-06-24 12:25:07

问题


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.


回答1:


Nohup will detach a process you run from your current console and let it continue when you close the terminal. Run something like this.

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 java -jar my.jar > /dev/null &



回答2:


This problem is not related to java, its actually something related to the way linux operates.

You need to do following:

nohup <your_application_command> &

Note the "nohup" and "&" at start and end respectively.




回答3:


You should be able to do something like:

nohup java -jar MyApplication.jar &



回答4:


On a linux machine you can create a service for your jar( executable jar like 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 


来源:https://stackoverflow.com/questions/9323690/run-a-java-program-in-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!