简体   繁体   中英

Executing jar with relative path from script

I'm trying to execute some Java code by using MacOS "scheduler" launchd .

My plist file:

<?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>net.nathangrigg.archive-tweets</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/ie54553/Desktop/MyProject/script.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>

    <key>StandardOutPath</key>
    <string>/tmp/out.out</string>
    <key>StandardErrorPath</key>
    <string>/tmp/err.out</string>
</dict>
</plist>

script.sh:

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -jar /Users/ie54553/Desktop/MyProj/classes/artifacts/jarFile_jar/Application.jar

The problem is, all the relative path I've in my program (resources path, properties, logs location, spring bean files etc) are fail.

The plist file is located under the root folder, therefore I assume that all the paths are relative to the executor location.

If the path starts with a '/' then its considered as an absolute path and treated as such. Is there a 'tmp' directory under '/' (and with write access) ? If not then try 'tmp' rather than '/tmp'.

From the docs :

For UNIX platforms, the prefix of an absolute pathname is always "/". Relative pathnames have no prefix. The abstract pathname denoting the root directory has the prefix "/" and an empty name sequence.

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