问题描述
创建可以在Linux上使用service运行的Java应用程序的最佳方法是什么?我打算在这里使用JSW ,但不能使用该许可证(许可证是GPL或据我所知,它需要花钱。我需要一个apache风格的许可证。
What is the best way to create a java application that can be run using ‘service’ on Linux? I was going to use the JSW available here, but cannot use the licence on that (licence is either GPL or it costs money as far as I can tell). I’d need an apache style licence.
我正在使用maven来构建,所以如果可以使用maven插件创建服务那就太棒了,但是任何其他建议都会很棒。
I’m using maven to build, so it would be great if it was possible to create the service using a maven plugin, but any other suggestions would be great.
我见过,有这个maven插件吗?文档看起来很稀疏,所以这个例子很好......
I've seen Apache Commons Daemon, is there a maven plugin for this? Documentation seems sparse, so a working example of this would be good...
谢谢
推荐答案
Linux上的服务只是启动后台进程的shell脚本。看看 /etc/init.d
- 您可以在文本编辑器中打开文件。你需要的只是一个bash脚本,它以适当的方式响应参数 start
和 stop
(例如。 start
将启动您的服务并将进程ID记录在已知位置, stop
将使用文件中的PID终止进程你创建了),然后把它放在 /etc/init.d
。
Services on Linux are just shell scripts which start background processes. Have a look in /etc/init.d
- you can open the files in a text editor. All you need is a bash script which responds to the parameters start
and stop
in an appropriate way (eg. start
will start your service and record the process ID in a known location, stop
will kill the process with the PID from the file you created), and then place it in /etc/init.d
.
看看和
这篇关于用于在Linux上创建Java守护程序服务的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!