Sample Mac Jar Bundler Ant build script

UPDATE: This approach is old and out of date. I’ll update it when I have time.

I was going to write a little tutorial on how to use the Jar Bundler Ant task for Mac OS X, but I don't have the time to do that right now.

So, I'll just share my Mac OS X Java Ant build script, which includes the JarBundler task. You should be able to use this Ant build script to build a Java application so it appears to the user to be a native Mac OS X application, even though it's really a Java application under the covers.

<project name="WikiTeX" default="do_bundle" basedir="..">

  <taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler" />

  <path id="class.path">
    <fileset dir="lib">
      <include name="**/*.jar"/>
      <include name="**/*.zip"/>
    </fileset>
  </path>

  <target name="init">
    <tstamp/>
  </target>

  <target name="create_classes_dir" depends="init">
    <mkdir dir="classes"/>
  </target>

  <target name="clean">
    <delete dir="classes"/>
  </target>

  <target name="compile" depends="clean,create_classes_dir">
    <javac destdir="classes" source="1.5" >
      <src path="src"/>
      <exclude name="**/_*.java"/>
      <classpath refid="class.path"/>
    </javac>
    <copy todir="classes">
      <fileset dir="src">
        <include name="**/*.gif"/>
        <include name="**/*.jpg"/>
      </fileset>
    </copy>
  </target>

  <!-- MAKE_JAR TARGET -->
  <target name="create_jar" depends="compile">
    <copy todir="classes/com/devdaily/opensource/jelly/view">
      <fileset dir="helpfiles">
        <include name="**/*.*"/>
      </fileset>
    </copy>
    <jar basedir="classes" jarfile="jar/wikitex.jar" manifest="build/rgadoc.manifest"/>
    <copy todir="jar">
      <fileset dir="lib">
        <include name="**/*.jar"/>
        <include name="**/*.zip"/>
      </fileset>
    </copy>
  </target>

  <target name="do_bundle" depends="create_jar">
    <!-- create a jar bundle for the mac -->
    <jarbundler dir="release"
                name="MyEditor"
                shortname="MyEditor"
                signature="Al Alexander"
                mainclass="com.devdaily.opensource.jelly.Main" 
                icon="build/wikitex.icns"
                jvmversion="1.5+"
                version="0.92"
                infostring="WikiTeX, v0.92, September 2007"
                build="2190"
                bundleid="com.devdaily.opensource.jelly.Main" >

      <jarfileset dir="jar">
        <include name="**/*.jar" />
        <exclude name="**/CVS" />
      </jarfileset>

      <javaproperty name="apple.laf.useScreenMenuBar" value="true"/>
      <javaproperty name="apple.awt.brushMetal" value="true"/>
      <javaproperty name="apple.awt.showGrowBox" value="false"/>
      <javaproperty name="com.apple.mrj.application.apple.menu.about.name" value="WikiTeX"/>
      <javaproperty name="apple.awt.textantialiasing" value="true"/>

    </jarbundler>
  </target>
</project>

One important note is that this Ant build script uses the Mac OS X JarBundler task. That is a separate task that you need to download so you can use this build script (or something like this build script).

Another thing to mention is that this script sets a number of Java properties within the jarbundler task, and all of these properties are Apple/Mac-specific. I've described these properties in other blog posts and tutorials, so if you'll search my site you should be able to find those.