Search code examples
javamacosbashshelllauncher

Mac launcher script for Java app


I need to launch a Jar file with a portable JRE. It works on Windows thanks to launch4j, it works on Ubuntu thanks to me, but not on Mac ..... and I can't test it.

The path tree of application:

    abcmap/
          launcher.command
          bin/
              abcmap.jar
              jre/
                  bin/
                      java

Thinking it's like Unix system, I tried this (without specify bash):

./bin/jre/bin/java -Xms512m -Xmx1024m -jar ./bin/abcmap.jar

But this error appear:

    MacBook-Pro:~ frcstnt$ /Applications/abcmap-mac/abcmap.command; 
    exit;
    /Applications/abcmap-mac/abcmap.command: line 1:
    bin/jre/bin/java: No such file or directory
    logout

All files are rwx for all,
All files are UTF8 without BOM
I tried to change end of line to Unix and to "Old Mac" with Notepad++,

Archives are available on my website:
http://abc-map.fr/download/
https://translate.google.fr/translate?hl=fr&sl=fr&tl=en&u=http%3A%2F%2Fabc-map.fr%2F

Someone can help me please?

Edit: I think my problem is in the launcher, maybe encoding or bad command ?

Edit: Thanks to the Wim's answer it works. This is the script:

#!/bin/bash 
SCRIPTDIR=$(dirname $0) 
cd $SCRIPTDIR 
${SCRIPTDIR}/bin/jre/bin/java -jar ${SCRIPTDIR}/bin/abcmap.jar

Solution

  • The path ./bin/jre/bin/java will be resolved relative to the current directory, not relative to the location of the command file. Try what happens if you run the command from the directory where the command is located.