[英]I would like to run my Java program on System Startup on Mac OS/Windows. How can I do this?
[英]How do you run a Java Web Start program at startup/logon using launchd on Mac OS?
我花了一段时间才弄清楚,我还没有在网上看到任何其他关于此的参考。
使用vi在如下路径创建文件:
~/Library/LaunchAgents/com.mycompany.myprogram.plist
该文件应包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.docuvantage.dvdesktop</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/javaws</string>
<string>-Xnosplash</string>
<string>http://www.mycompany.com/pub/myprogram.jnlp</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
验证文件语法如下:
plutil -lint ~/Library/LaunchAgents/com.mycompany.myprogram.plist
测试配置:
launchctl load ~/Library/LaunchAgents/com.mycompany.myprogram.plist
卸载,以便您可以再次测试:
launchctl unload ~/Library/LaunchAgents/com.mycompany.myprogram.plist
您必须将AbandonProcessGroup设置为true才能使launchd不会终止您的应用程序。 javaws可执行文件分叉几次并创建子进程,然后javaws退出。 默认情况下,launchd会看到该程序退出并终止它生成的所有子进程。
不要试图为javaws使用-wait
开关。 这是行不通的。
因为-wait
不起作用,所以无法使用KeepAlive
设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.