Run Java console app as a daemon (background)

人盡茶涼 提交于 2019-11-28 20:54:49

The answer is operating system dependent.

*nix: <your command> &
Windows: (opens a new console): start <your command>
Windows: (doesn't open a new console): start /b <your command>

If you are doing this in anything unix based then you can append & to the end which will spawn a new thread and keept it running in the background.

java -jar myapp.jar &

If you really just want it to run in the background, java -jar myapp.jar & will do the job. That way, it'll still die when the shell closes, but you can keep using your shell.

If you really want it run as a daemon, nohup java -jar myapp.jar & will do the job. That way, it'll continue to live when the shell closes.

If you want this to be reliable, you can prepare an init script or upstart job definition, or run it via Vixie cron(8) @reboot specifier to make it start at boot.

Given that you're using Windows, you might consider Java Service Wrapper. I have used it on a project in the past.

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