UNIX 平台上的系统启动文件夹/方法?
我有一个 Java 应用程序,需要实现在启动时启动 JAR 的安装功能。
我可以通过在注册表中输入 REG 文件来在 Window 上执行此操作,但如何在 UNIX 平台上执行此操作? Linux和Mac如果方法不同。
Linux和Mac有系统启动文件夹吗?
请记住,我需要以编程方式执行此操作,而不是通过系统首选项或类似的东西。
I have a Java application that needs to implement installation features of making a JAR launch on startup.
I can do this on Window by entering a REG file into the registry, but how can I do this on UNIX platforms? Linux and Mac if the methods are different.
Do Linux and Mac have system startup folders?
Remember that I need to do this programmatically not through system preferences or anything like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Linux 上,经典方法是在相应的
/etc/rcN.d/
目录中添加脚本(其中 N 是代表“运行级别”的数字 0-6)。我不确定这是否仍然是推荐的方式,但通常仍然受支持。这也适用于其他主流 Unix 变体(Solaris、HP-UX、AIX)的微小变化。在 Mac 上,你必须更加努力。文件
/etc/rc.common
、/etc/rc.imaging
和/etc/rc.netboot
是相关的,但没有/etc/rcN.d
目录。还有一个脚本rc
和另一个rc.local
。输入man rc
显示:因此,您应该研究
launchctl
和launchd
,特别是launchctl
。On Linux, the classic way would be through adding a script in the appropriate
/etc/rcN.d/
directory (where N is a number 0-6 representing the 'run level'). I'm not sure whether that's still the recommended way, but it usually is still supported. This would also work with minor variations for other mainstream Unix variants (Solaris, HP-UX, AIX).On Mac, you have to work harder. The files
/etc/rc.common
,/etc/rc.imaging
and/etc/rc.netboot
are related, but there are no/etc/rcN.d
directories. There's also a scriptrc
and anotherrc.local
. Typingman rc
reveals:So, you should investigate
launchctl
andlaunchd
, particularlylaunchctl
.这就是我在 ubuntu 上的做法。
首先创建一个bash脚本来运行java应用程序,类似于。
并保存它,在本例中称为 /etc/init.d 中的“HELLOWORLD”。
需要使脚本可执行,因此需要运行
Final 使其在启动时运行
This is how I would do it on ubuntu.
First create a bash script to run the java app, similar to.
and save it, in this case called 'HELLOWORLD' in /etc/init.d.
Need to make the script executable so need to run
Finally to make it run on start up
在 Mac 上我认为是
launchd
,在 Linux 上是init.d
。它们是配置文件。On Macs I think its
launchd
, and on linux itsinit.d
. They are config files.