HOWTO: Package Your Natively Compiled Java Application as An OS X Application Bundle. This document contains instructions for packaging your natively compiled Java application into an OS X application bundle. After creating a package bundle, you can submit it to Mac App Store or publish it on your website.
Yes, on Mac OS X there is a program called that is installed when you install the free (assuming that you already own a copy of Mac OS X) that allows you to bundle a JAR file inside a native Mac OS X '.app' application bundle with a nice and shiny icon just like other apps. Update The JAR bundler doesn't exist on later versions of OS X. As a workaround, you can manually create an OS X project that invokes Java. Or, there are a variety of build system extensions that do a similar thing; for example, the plugin for Gradle will create such a wrapper app.
Deploying SWT Applications on Mac OS X Under Mac OS X, applications are stored in an application bundle, which is simply a directory containing the executable and any associated resources for an application. An application bundle has the extension.app and appears as a single file in the Finder. These application bundles are usually distributed inside compressed disk images with the extension.dmg. Disk images are automatically mounted on download, presenting the user with the bundle icon so it can be dragged to their Applications folder. More information on application bundles and disk images can be found in the section of the Apple documentation. (1.4MB) is a disk image of a simple SWT Hello World application. What's in the.app directory The SWTHello.app directory contains the following files: SWTHello.app/Contents/Info.plist SWTHello.app/Contents/Resources/swthello.icns SWTHello.app/Contents/MacOS/swthello SWTHello.app/Contents/MacOS/SWTHello.class SWTHello.app/Contents/MacOS/swt/libswt-.jnilib SWTHello.app/Contents/MacOS/swt/swt.jar is an XML file describing the application name and description, vendor, icon, and executable to run.
The Property List Editor application can be used to edit this file. The.icns file is our icon, and swthello is a small shell script. The SWT.jar and.jnilib files are from the Mac OS X download of SWT from the.
Launching the application In the SWTHello example, a small shell script is used as the executable to run. This allows us to easily launch Java with any required options.
#!/bin/sh BASEDIR=`dirname $0` exec java -d64 -XstartOnFirstThread -classpath $BASEDIR/swt/swt.jar:$BASEDIR SWTHello (NOTE: If you are using eclipse 3.2.2 or earlier, you also need -Djava.library.path=.) The shell script launches java with the required classpath and Java library path settings to use SWT. The -d64 switch ensures that the 64-bit JVM is used; if swt.jar contains either the Carbon or 32-bit Cocoa port of SWT then -d32 should be specified instead. The special VM option -XstartOnFirstThread is also required for SWT applications to run properly on the Mac. Creating a disk image Disk images can be created on the command line using hdiutil or graphically using the Disk Utility application. Hdiutil create -srcfolder SWTHello SWTHello.dmg hdiutil internet-enable -yes SWTHello.dmg A DMG file can optionally be 'internet-enabled', which streamlines the installation process, automatically mounting and copying the application to the Desktop. Now that wasn't so bad, was it?