简体   繁体   中英

How do you run a Java Web Start program at startup/logon using launchd on Mac OS?

我花了一段时间才弄清楚,我还没有在网上看到任何其他关于此的参考。

Use vi to create a file at a path like this:

~/Library/LaunchAgents/com.mycompany.myprogram.plist

The file should contain this:

<?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>

Verify the file syntax like this:

plutil -lint ~/Library/LaunchAgents/com.mycompany.myprogram.plist

Test the configuration:

launchctl load ~/Library/LaunchAgents/com.mycompany.myprogram.plist

Unload so you can test again:

launchctl unload ~/Library/LaunchAgents/com.mycompany.myprogram.plist

You must set AbandonProcessGroup to true to keep launchd from killing your application. The javaws executable forks a couple times and creates sub-processes and then javaws quits. By default launchd then sees that the program quit and kills all the sub-processes that it spawned.

Do not bother trying to use the -wait switch for javaws. It does not work.

Because -wait does not work you cannot use the KeepAlive setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM