How to build a Mac Java app (OS X 10.9+ and Java 7+)

As a quick note to self, I used the following Ant build.xml file in 2014 to build my Wikipedia Reader client application on Mac OS X 10.9 with Java 7.x:

<project name="WikiReader" default="create-bundle" basedir=".">

  <taskdef name="bundleapp" classname=""/>
  <property environment="env"/>

  <!-- input stuff -->
  <property name="current.dir" value="." />
  <property name="scala-lib.dir" value="scala-libs" />

  <!-- output stuff -->
  <property name="release.dir" value="release" />

  <!-- clean -->
  <target name="clean">
    <echo message="clean task ..." />
    <!-- just needed for the first-time run -->
    <mkdir dir="${release.dir}"/>
    <!-- remove the old version of the app -->
    <delete dir="${release.dir}/" />

  <!-- create mac osx 'bundle' -->
  <target name="create-bundle" depends="clean">
  <bundleapp outputdirectory="${release.dir}"
        copyright="Alvin J. Alexander"

        <runtime dir="${env.JAVA_HOME}" />

        <!-- the only jar file needed when using sbt-assembly -->
        <classpath file="../target/scala-2.10/WikiReaderClient-assembly-0.1.jar" />

        <option value="-Xdock:icon=Contents/Resources/WikiReader.icns"/>
        <option value="-Dapple.laf.useScreenMenuBar=true"/>
        <option value=""/>
        <option value=""/>
        <option value=""/>
        <option value=""/>



Once my Scala/Java application is built with this build script, I can run it just like any other Mac OS X application.

Note that I use sbt-assembly to compile my Scala application and convert it into one jar file before running this Ant build script. You can see it referenced as the WikiReaderClient-assembly-0.1.jar file.

(In the real world I have a shell script that (a) builds the application with SBT and sbt-assembly, and (b) runs Ant with this build script to (c) bundle my Mac application. You might be able to do all of that with SBT alone, but I haven’t looked into that.)

This script uses the Oracle “appbundler” technology that’s built into their OS X JDK. You can read more about how this works at this Oracle/Java URL.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.