简体   繁体   中英

Run a java program in backend

大家好,我想运行一个 java 应用程序作为后端进程。这就像 tomcat 服务器。为此,我开发了一个应用程序。并将一个类作为主类并从一个脚本文件调用 .ie(startup.sh) file.in startup.sh 文件我正在调用一个类。即 MainMethodClass。在主方法类中,我编写了我的业务逻辑。当我在 linux 服务器中使用腻子运行此应用程序时,它一直在工作,直到腻子窗口未关闭。在关闭之后腻子窗口它也停止了。但是即使我关闭了我也需要运行这个应用程序。我怎样才能做到这一点。

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 &

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.

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 

您应该能够执行以下操作:

nohup java -jar MyApplication.jar &

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM