Bundling a Java tool into an OS X application

A quick reminder to myself about bundling a Java tool into an OS X application.

Directory structure

JConsole.app
JConsole.app/Contents/
JConsole.app/Contents/Info.plist
JConsole.app/Contents/MacOS/
JConsole.app/Contents/MacOS/Run.sh
JConsole.app/Contents/Resources/
JConsole.app/Contents/Resources/Application.icns

Info.plist

<?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>CFBundleExecutable</key>
    <string>Run.sh</string>
</dict>
</plist>

Run.sh

#!/bin/bash

APP_DIR=$(dirname $(dirname $(dirname $0)))
APP_NAME=$(basename $APP_DIR .app)

$(/usr/libexec/java_home -v 1.8)/bin/jconsole \
-J-Dapple.laf.useScreenMenuBar=true \
-J-Dapple.awt.antialiasing=true \
-J-Xdock:name="$APP_NAME" \
-J-Xdock:icon="$APP_DIR/Contents/Resources/Application.icns" \
-J-Dcom.apple.mrj.application.apple.menu.about.name="$APP_NAME"