launchd: Managing a Java Jar

2019-07-11 03:48发布

问题:

I have the following launchd configuration (stored in acme.plist) which I load and start using launchctl load acme.plist and launchctl start acme.plist respectively.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.acme</string>

    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/java</string>
        <string>-jar /usr/local/acme/acme-latest.jar</string>
    </array>

    <key>StandardErrorPath</key>
    <string>/tmp/acme-error</string>
</dict>
</plist>

Whenever I try to run it, I get the following in /tmp/acme-error:

Unrecognized option: -jar /usr/local/acme/acme-latest.jar
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Yet I have absolutely no problems when running from bash. Any ideas?

回答1:

You should change your config like so:

<key>ProgramArguments</key>
<array>
    <string>/usr/bin/java</string>
    <string>-jar</string>
    <string>/usr/local/acme/acme-latest.jar</string>
</array>