Jar to Mac OSX App Bundle with app bundler

Okay, so, after having a little play around, this is what I understand…

  • Download Java Application Bundler and place it in the lib directory of your project. You will need to create this directory…
  • Create a new Ant script into your project directory, call it what ever you like…Also, take the time to read through the AppBundler Task Docs

The ant script should be based on the following skeleton…

<project name="ButtonDemo" default="bundle-buttonDemo" basedir=".">        
    <taskdef name="bundleapp"
             classname="com.oracle.appbundler.AppBundlerTask"   
             classpath="lib/appbundler-1.0.jar" />
    <!-- See the lib reference here, this is why you need to use the lib directory! -->

    <target name="bundle-buttonDemo">
        <delete dir="appBundle" failonerror="false"/>
        <mkdir dir="appBundle"/>
        <bundleapp outputdirectory="appBundle"
            name="ButtonDemo"
            displayname="Button Demo"
            identifier="components.ButtonDemo"
            mainclassname="components.ButtonDemo">
            <!-- The following is important and should point to your build -->
            <classpath file="dist/ButtonDemo.jar" />
            <!-- You can have multiple instance of classpath if you 3rd party or
                 dependent jars in different locations -->
        </bundleapp>
    </target>
</project>
  • Build your project
  • Run the ant script, using (something like) ant -f {You App Bundler script}

The app bundle, in this case ButtonDemo.app will be created in appBundle directory. If you can, browse the contents of the ButtonDemo.app/Contents/Java and make sure all your required Jar files are there…

Happy bundling!

Updated based on updated build.xml file

1- There is no default target specified by the project tag. Think of this like your “main class” or “main” method, without, ant has no idea what you want to run…

<project name="Rage Mage" basedir="." default="bundle-RageMage">

2- The name of the taskdef is significant and you use it in the any script to identify what ant should do when it hits your tag reference…

So based on your example, you either need to change the name of the taskdef from ragemage to bundleapp or change the bundleapp tag to ragemage

Either change this…

<taskdef name="bundleapp"
     classname="com.oracle.appbundler.AppBundlerTask"   
     classpath="lib/appbundler-1.0.jar" />

or this (in target bundle-RageMage)

<ragemage outputdirectory="bundle"
    name="Rage Mage"
    displayname="Rage Mage"
    icon="res/icon.icns"
    identifier="ragemage.src.Window"
    mainclassname="ragemage.src.Window">
    <classpath file="dist/ragemage_1.1.1.jar" />
</ragemage>

Personally, I’d leave it as bundleapp, but that’s me…

3- The delete, mkdir and outputdirectory attribute of bundleapp are related…

<delete dir="appBundle" failonerror="false"/>
<mkdir dir="appBundle"/>
<bundleapp outputdirectory="bundle"...

Either, make them all appBundle or bundle, what every you want…

4- You main class is unlikely to be ragemage.src.Window and is probably going to be Window

Leave a Comment