如何为Mac OS X编写启动脚本?

时间:2021-07-05 01:08:21

I have created a jar file in java, and I want to make the application automatically start during system boot up. I found I have to write a shell script for that. What should be that shell script look like? Is there anything else I have to do to make an application automatically start at boot up?

我在java中创建了一个jar文件,我希望在系统启动期间自动启动应用程序。我发现我必须为此写一个shell脚本。shell脚本应该是什么样子?我还需要做什么才能让应用程序在启动时自动启动?

3 个解决方案

#1


11  

The preferred way to launch programs at OS X startup is to create a launchd daemon as explained here.

在OS X startup中启动程序的首选方式是创建一个launchd守护进程。

#2


2  

In mac os x you can also just run "open program.jar" (or any folder, '-a' for native applications) and it will open detached from the terminal with any default environment settings that it would use if you just double clicked it.

在mac os x中,你也可以运行“open program”。jar“(或任何文件夹,'-a',用于本机应用程序),它将打开与终端分离的,具有任何默认的环境设置,如果您双击它,它将使用这些设置。

You can also add a program (or the script) to the user's login items through System Preferences > Accounts > 'username' > Login items. This is completely point and click and doesn't require a shell script

您还可以通过系统首选项>来添加一个程序(或脚本)到用户的登录项,>帐户> '用户名' >登录项。这完全是指向和单击,不需要shell脚本

#3


0  

The shellscript would be something like this:

外壳应该是这样的:

cd /directory/to/jar
java -jar Jar.jar

Or maybe you don't actually need to write Jar.jar, only Jar. I don't quite remember.

或者你实际上不需要写Jar。jar,只有jar。我不太记得了。

#1


11  

The preferred way to launch programs at OS X startup is to create a launchd daemon as explained here.

在OS X startup中启动程序的首选方式是创建一个launchd守护进程。

#2


2  

In mac os x you can also just run "open program.jar" (or any folder, '-a' for native applications) and it will open detached from the terminal with any default environment settings that it would use if you just double clicked it.

在mac os x中,你也可以运行“open program”。jar“(或任何文件夹,'-a',用于本机应用程序),它将打开与终端分离的,具有任何默认的环境设置,如果您双击它,它将使用这些设置。

You can also add a program (or the script) to the user's login items through System Preferences > Accounts > 'username' > Login items. This is completely point and click and doesn't require a shell script

您还可以通过系统首选项>来添加一个程序(或脚本)到用户的登录项,>帐户> '用户名' >登录项。这完全是指向和单击,不需要shell脚本

#3


0  

The shellscript would be something like this:

外壳应该是这样的:

cd /directory/to/jar
java -jar Jar.jar

Or maybe you don't actually need to write Jar.jar, only Jar. I don't quite remember.

或者你实际上不需要写Jar。jar,只有jar。我不太记得了。