I have been using Java Application Bundler to pack a Java application as .app. I have managed to run the application if I pack the JRE7 inside of the .app bundle. Is it poss
appbundler
applications can use either an embedded Java 7 JRE inside the app bundle, or the Java 7 JRE installed in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
(the same one used by the web browser plugin). They can't use a JDK installed under /Library/Java/JavaVirtualMachines
(or anywhere else, for that matter) and they definitely can't use Java 6.
What you can do, however, is not use appbundler
and instead build the bundle by hand, with the main executable being a shell script that runs the java
command line tool from JAVA_HOME
(maybe falling back to the /Library/Internet Plug-Ins
JRE if JAVA_HOME
is not set). Such a script will be able to support both Java 6 and 7.
You would use something like this as YourApp.app/Contents/MacOS/YourApp
:
#!/bin/sh
PRG=$0
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
progdir=`dirname "$PRG"`
if [ -n "$JAVA_HOME" ]; then
JAVACMD="$JAVA_HOME/bin/java"
elif [ -x /usr/libexec/java_home ]; then
JAVACMD="`/usr/libexec/java_home`/bin/java"
else
JAVACMD="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
fi
exec "$JAVACMD" -classpath "$progdir/../Resources/Jars/*" \
-Dapple.laf.useScreenMenuBar=true \
my.pkg.MainClass
Then put your application's JAR files in YourApp.app/Contents/Resources/Jars
, the icon in YourApp.app/Contents/Resources/icon.icns
, and the following in YourApp.app/Contents/Info.plist
:
CFBundleDevelopmentRegion
English
CFBundleExecutable
YourApp
CFBundleGetInfoString
My clever application
CFBundleIconFile
icon.icns
CFBundleInfoDictionaryVersion
8.0
CFBundleName
YourApp
CFBundlePackageType
APPL
CFBundleSignature
????
CFBundleVersion
8.0
See the GATE Developer launcher for full details, though note that this is a slightly more convoluted case as the .app
script delegates to another script, which in turn loads the JAR files from a location that is outside the .app
bundle. The principle remains the same however.