This is how I managed to do it. I use NetBeans to compile to a .jar file. You also need to have the Java jdk1.7.0_45.jdk installed.
A) Download apache-ant-1.9.3-bin.tar.gz from http://ant.apache.org/bindownload.cgi to your Downloads folder
B) In the terminal do the following (taken with some changes from http://stackoverflow.com/questions/3222804/how-can-i-install-apache-ant-on-mac-o s-x)
cd ~/Downloads # Let's get into your downloads folder.
tar -xvzf apache-ant-1.9.3-bin.tar.gz # Extract the folder
sudo mkdir -p /usr/local # Ensure that /usr/local exists
sudo cp -rf apache-ant-1.9.3 /usr/local/apache-ant # Copy it into /usr/local
# Add the new version of Ant to current terminal session
export PATH=/usr/local/apache-ant/bin:"$PATH"
# Add the new version of Ant to future terminal sessions
echo 'export PATH=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile
C) Get appbundler-1.0.jar from http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.h tml
There is some good detailed information there also about bundling.You may need to set your JAVA_HOME parameter.
D) Then comes the bundling procedure:
1) Compile your source code to get a .jar file in the dist folder.
2) Make a bundle file or if you use Netbeans, edit the file build.xml in the top project folder.
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="bundle">
<bundleapp outputdirectory="dist"
name="MySourceName"
displayname="MySourceName"
identifier="package.MySourceName"
mainclassname="package.MySourceName">
<classpath file="dist/MySourceName.jar" />
<option value="-Dapple.laf.useScreenMenuBar=true"/>
</bundleapp>
</target>
Edit the above text in some simple text editor and exchange MySourceName with your project name and “package” with your package name. The line <option value="-Dapple.laf.useScreenMenuBar=true"/> will make your menu be placed in the Mac style.
Note! Beware of the difference “ and ". The corrrect one is the latter. TextEdit changed my hyphens to the bad ones which screwed up the bundling..
The edited file should reside in the top project folder under the name build.xml.
3) Place the appbundler-1.0.jar in a new “lib” folder in the top project folder.
4) Run terminal . Go to your Netbeans project folder using the cd command. The do
ant bundle
and wait for BUILD SUCCESSFUL
The bundled Mac application will reside in the dist folder.
How to fix a specific icon to the application:
5) Open the bundled Mac application by CTRL-click and choose “Show Package Contents”
6) Double-click the Contents folder to open it. Put your tailor-made application icon “XXX.icns” in the Resources folder. Open the Info.plist and change Generic.icns to XXX.icns. Close the application folders. Sometimes the icon will only show up afterf you copy the application to another folder
Optional (This will make your application very big as it includes the Java jdk in the application, I didn't do this step. The only advantage is that it will make the application independent on the user having Java installed.a )
7) To include the jdk, open the app folder and put a copy of the jdk1.7.0_45.jdk in the Plugins folder.
Edit the Info.plist by adding a new child: JVMRuntime containing a string, jdk1.7.0_45.jdk