Mac OS X JarBundler ANT Task

Version 2.3.1

How many times has this happened to you? You've written a little Java utility, or maybe even a more complex application, and you want to create Mac OS X application bundle for easy distribution.

You'd like to be able to do it automatically from your build process, but you're forced to go run the Apple Jar Bundler and tweak all the settings manually every time you build.

Well no more! JarBundler is a feature-rich Ant task which will create a Mac OS X application bundle from a list of Jar files and a main class name. You can add an Icon resource, set various Mac OS X native look-and-feel bells and whistles, and maintain your application bundles as part of your normal build and release cycle. It is free software licensed under the GNU General Public License.

This release is based on the earlier work of Seth Morabito.

This project was taken over by Tobias Bley and moved to GitHub August 2015.

What's New, April 2014

Download

Source and binary, all platforms (ZIP): jarbundler.zip
Source and binary, all platforms (TAR): jarbundler.tar.gz

Installation

Move the file jarbundler-2.3.1.jar into your local ANT lib directory. Remove any older versions at this time.

Using in the Build file

To use the Jar Bundler Ant Task, create a task definition in your ANT build.xml file like this:

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

Now, from a target, you can add the "jarbundler" task.

<jarbundler dir="release"
            name="MyApp"
            mainclass="org.foo.myapp.Main" 
            jar="myapp.jar" />

Task Attributes, required

Attribute Description
dir The directory in which your application bundle will be created.
name The name of your application bundle (minus the ".app" extension).
mainclass The name of the main class to run when the application bundle is launched.
The corresponding bundle variable is MainClass
jar A single jar file to be used in your application.
Not Required if there are nested <jarfileset> or <jarfilelist> nested tasks.
Can be used with nested <jarfileset> and/or <jarfilelist> tasks i.e. all jar files will be added to the class path.

Task Attributes, optional

Attribute Description
allowMixedLocalizations If true, the bundle supports the retrieval of localized strings from frameworks. This should be set to true if your app supports different languages.
The corresponding bundle variable is CFBundleAllowMixedLocalizations
Default: false
arguments Extra command-line arguments for the Java application.
The corresponding bundle variable is Arguments
build Application build number. This string is used in the default "About..." box along with the 'version' number. This default About Box format is "version (build)" i.e. "4.3.1 (231)". Also see version and infostring attributes.
The corresponding bundle variable is CFBundleVersion
Default: the value of the version attribute
bundleid Unique identifier string for the bundle. This string should be in the form of a java package name, for example com.apple.myapp.
The corresponding bundle variable is CFBundleIdentifier
copyright A string with the copyright notice for the bundle; for example "©2014, My Company"
The corresponding bundle variable is NSHumanReadableCopyright
developmentregion The development region of the bundle.
The corresponding bundle variable is CFBundleDevelopmentRegion
Default: English
extraclasspath A list of files or patternsets (space or comma seperated) to add to the bundle's classpath. The files referenced by this property will not be copied into the bundle, so the resulting .app may only work on systems that have these external resources available.
helpbookfolder Specify the directory name of the Help Book in the "resources" directory. When this name must match the directory name when using the <resourcefileset> task to copy the Help Book HTML files into the bundle.
The corresponding bundle variable is CFBundleHelpBookFolder
helpbookname Specify the name of the Help Book. This is string is also used as the META tag to designate the initial HTML file to be loaded into the Help Viewer application.
<meta name="AppleTitle" content="Hello World Help"/>
NB: The Apple Help Book system does not open the file index.html by default. Although it is a good practice to use this filename with the embedded META tag shown above.
The corresponding bundle variable is CFBundleHelpBookName
icon File reference to a Mac OS X icon file. This file is created with the Mac OS application located at "/Developer/Applications/Utilites/Icon Composer"
infostring A string for display in the Finder's Get Info panel. Also see version and build attributes.
The corresponding bundle variable is CFBundleGetInfoString
Default: the value of the version attribute
isAgent boolean
jvmarchs A space delimited string. Used to take advantage of 64-bit computing.
Example: jvmarchs="i386 x64_86 ppc"
lsArchitecturePriority A space delimited string. Contains an array of strings identifying the supported code architectures and their preferred execution priority.
Example: jvmarchs="i386 x64_86 ppc"
jvmversion The version of the JVM required to run the application. Typically a string in the form "1.3", "1.3+", "1.4", "1.4+", etc.
The corresponding bundle variable is JVMVersion
Default: 1.3+
shortname The string used in the application menu.
This string is often shorter than the application's name. For example, "Microsoft Word" displays "Word".. Apple recommends that this string be limited to 16 characters. JarBuilder enforces this limit silently by truncating shortname. If the shortname is not specified then the application's name will be used with no truncation.
showplist If true, display the contents of the Info.plist file
Default: false
signature The four-letter code identifying the bundle.
The corresponding bundle variable is CFBundleSignature
Default: ????
splashfile **Needs link to Apple Technical Document**
stubfile If set, the location of a Mac OS X Java Application Stub file to use for this application bundle. See the section "Specifying the Java Launching Stub File" below.
Required for Windows or Linux
Under MacOS, if the referenced file does not exist, then the file name will be used in the bundle to reference a copy of the JavaApplicationStub. This usage provides a way for each Java application to have a uniquely named executable file name. This is useful when using the UNIX 'top' command to distinguish applications.
suFeedURL Used to check for new version of the applications.
verbose If true, output more verbose information to Ant while the task is running.
Default: false
version Version number displayed in Finder, this version number can be though of as the "Marketing" version without distracting build information. The marketing version is a string that usually displays the major and minor version of the bundle. This string is usually of the form n.n.n where n is a number. Also see build and infostring attributes.
The corresponding bundle variable is CFBundleShortVersionString
Default: 1.0
vmoptions Command line options to pass the JVM at startup.
The corresponding bundle variable is VMOptions
workingdirectory The working directory for the Java application.
The corresponding bundle variable is WorkingDirectory
startOnMainThread
Valid values 'true' or 'false'.

Task Attributes, deprecated

Attribute Description
aboutmenuname The string to display in the "About" menu of the running application. (Deprecated under JVM 1.4.1)
Use JarBundler attribute shortname instead
antialiasedgraphics If set to true, use anti-aliasing when rendering graphics.
Use <javaproperty name="apple.awt.antialiasing" .../>
antialiasedtext If set to true, use anti-aliasing when rendering text.
Use <javaproperty name="apple.awt.textantialiasing" .../>
chmod The full path to the BSD 'chmod' command.
Using the ANT task "Chmod" internally.
execs A list of files or patternsets (space or comma seperated) to place into the "Resources/MacOS" directory and set executable.
Usage Warning: Filenames and directory paths can sometimes contain spaces and commas. If these characters are present the build will fail mysteriously when using this attribute.
Use <execfileset/> or <execfilelist/> nested tasks instead.
growbox Show the Aqua resize (grow) box.
Use <javaproperty name="apple.awt.showGrowBox" .../>
growboxintrudes Resizable window's growbox (resize control) intrudes into AWT content. If turned off, the bottom of the window is pushed down 15 pixels. (Deprecated under JVM 1.4.1)
jars A list of jar files or patternsets (space or comma seperated) to be used in your application.
Usage Warning: Filenames and directory paths can sometimes contain spaces and commas. If these characters are present the build will fail mysteriously when using this attribute.
Use <jarfileset> and/or <jarfilelist> nested tasks instead.
type The Mac OS type of the bundle.
This attribute is redundant with the implied behavior this ANT task i.e. CFBundlePackageType should always be set to APPL for applications.
shortinfostring Use infostring attribute instead.
smalltabs If set to true, tab controls in Swing applications more closely resemble the Metal look and feel. If set to false, the tabs assume a larger size more similar to the default Aqua controls. (Deprecated under JVM 1.4.1)
liveresize If set to true, enable live-resizing of windows. (Deprecated under JVM 1.4.1)
screenmenu If set to true, puts Swing menus in the Mac OS X menu bar if using the Aqua look and feel.
Set the apple.laf.useScreenMenuBar property instead: <javaproperty name="apple.laf.useScreenMenuBar" value="true"/>

Nested DataType Task

<jarfileset>

The nested jarfileset element specifies a FileSet. All files included in this fileset will be included in the application bundle and added to the app bundle classpath. Only required if the jars attribute is not set.

<jarfilelist>

The nested jarfilelist element specifies a FileList. All files included in this filelist will be included in the application bundle and added to the app bundle classpath. Only required if the jars attribute is not set.

<javaproperty ...>

This ANT DataType element allows developers to specify java properties for the info.plist. This DataType repalces many jarbundler tag attributes. However, if a deprecated attribute is used it will take precedent over a javaproperty. This was done to maintain backward compatibility with earlier versions of jarbundler.

This task takes name/value pairs:

<javaproperty name="apple.awt.showGrowBox" value="true"/>

Additional Java Properites can be found in the Apple Developer Connection document:   Apple Java Properties for JDK 1.4+

<execfileset>

The nested execfileset element specifies a FileSet. All files included in this fileset will be added to the application bundle's "Contents/MacOS" directory and set executable. Optional.

<execfilelist>

The nested execfilelist element specifies a FileList. All files included in this filelist will be added to the application bundle's "Contents/MacOS" directory and set executable. Optional.

<resourcefileset>

The nested resourcefileset element specifies a FileSet. All files included in this fileset will be added to the application bundle's "Contents/Resources" directory. Optional.

<resourcefilelist>

The nested resourcefilelist element specifies a FileList. All files included in this filelist will be added to the application bundle's "Contents/Resources" directory. Optional.

<javafileset>

The nested javafileset element specifies a FileSet. All files included in this fileset will be added to the application bundle's "Contents/Resources/Java" directory. Optional.

<javafilelist>

The nested javafilelist element specifies a FileList. All files included in this filelist will be added to the application bundle's "Contents/Resources/Java" directory. Optional.

<extraclasspathfileset>

The nested extraclasspathfileset element specifies a FileSet. All files included in this fileset will be added to the application bundle's classpath, but the files will not be copied into the bundle itself. This allows you to specify external system classpath dependencies without bundling the resources. Resources can be files or directories. Optional.

<extraclasspathfilelist>

The nested extraclasspathfilelist element specifies a FileList. All files included in this filelist will be added to the application bundle's classpath, but the files will not be copied into the bundle itself. This allows you to specify external system classpath dependencies without bundling the resources. Resources can be files or directories. Optional.

Note on FileList and FileSet target locations

Note that in fact the files are installed in locations which have the same relation to either Contents/MacOS or Contents/Resources directories as the files in the FileSet or FileList have to the 'dir' attribute. Thus in the case:

 <resourcefileset dir="builddir/architectures" includes="ppc/*.jnilib"/>

the *.jnilib files will be installed in Contents/Resources/ppc

Examples

A minimal example might look like this

 <jarbundler dir="release"
             name="MyApp"
             mainclass="org.foo.myapp.Main"
             jar="build/myapp.jar" />

This will create a Mac OS X application bundle called "MyApp.app" in the directory "release" using a JAR file which was created in the "build" directory.

You can use FileSets or FileLists for more complex builds. For example:

<jarbundler dir="release"
            name="MyApp 1.0"
            mainclass="org.foo.myapp.Main" >

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

  <jarfilelist dir="lib" file="GUI.jar, Utils.jar" />

</jarbundler>

Advanced JarBundler Tasks

Associating Documents with your Application

Including an Apple Help Book

Apple System Service Property

Java Launching Stub File

Advanced Example

Creating a Disk Image

History

Released: Dec 2010 (version 2.2.0)

Released: Oct 2008 (version 2.1.0)

Released: Jan 2007 (version 2.0.0)

June 19, 2006 (version 1.9)

April 12, 2006 (version 1.8.1)

Fix bug when using localized Help Books, the menu application would appears as (null)

Corrected the encoding for the Info.plist XML file so that the copyright character, amongst others, are processed correctly. Thanks to Christian Roth for both pointing out the encoding problem and providing a one line solution!

April 11, 2006 (version 1.8)

Added bundle attribute to documenttype task in order to specify documents which are in reality directory trees, yet treated as a single entity by the Finder. Thanks to Deerwood McCord Jr. for the implementation.

Added mimetypes attribute to documenttype task in order to specify Multipurpose Internet Mail Extensions (MIME) types for the document. Thanks to Deerwood McCord Jr. for the implementation.

No longer required to delete the existing application bundle, i.e. .app directory, before invoking the jarbundler task. This is now done by the task itself.

The filename of the stubfile attribute will be used as the Java Application Stub filename within the bundle and for the value of the CFBundleExecutable key in the Info.plist. This usage provides a way for each Java application to have a uniquely named executable filename. This is useful when using the UNIX 'top' command to distinguish applications. Thanks to Deerwood McCord Jr. for the this idea.

Info.plist is built internally as a DOM tree instead of concatenating strings. This resulting DOM tree is serialized into the file using two space indentation and one tag per line.

Improved readablity of the verbose output. The contents of the Info.plist file is controlled by the showPlist attribute.

Reorganize JarBundler documentation by splitting out advanced features

March 22, 2006 (version 1.7)

Added <documenttype> nested task so that file associations can be set up for the application. Thanks to Dan Stowell a sample "Info.plist" file containing document type entries.

Added <javafileset> and <javafilelist> nested tasks, which mirror <resourcefileset> and <resourcefilelist>, in order to add files to the Contents/Resources/Java directory

Added Apple Help Book support by...

Thanks to Will Lowe for an example Help Book project with JNI code.

Split the "Hello, World" example into a complex build which associates document types and uses a Help Book, and a simple minimal build

Reorganize 'example' source directory to include Objective-C JNI code and use package structure for "Hello, World" application rather than putting everything

March 2, 2006 (version 1.6)

Added <resourcefileset> and <resourcefilelist> nested elements, which mirror <execfileset> and <execfilelist>, and add files to the Contents/Resources directory.

Added build attribute to jarbundler task. See also version and infostring for usage.

Added jar attribute to jarbundler task.

Added shortname attribute to jarbundler task. See also name for usage.

JarBundler is now a SourceForge project!

Changed task package to net.sourceforge.jarbundler

February 2006 (version 1.5)

Changed the package from 'com.loomcom.ant.tasks.jarbundler' to 'com.informagen.ant.tasks.jarbundler' so that version 1.4 can remain installed without conflict

Added a nested DataType called "javaproperty" so that new properties can be added by end users and deprecated properties can be removed. Former jarbundler tag atributes are still available but have been deprecated in favor of their 'javaproperty' equivalents.

Currently, a jarbundler tag attribute overrides a javaproperty tag. This was done to maintain backward compatibility with version 1.4

13 November 2004 (version 1.4):

Fixed a bug that was causing application arguments not to be set.

23 October 2004 (version 1.3):

Added "extraclasspath" attribute, and "extraclasspathfileset" and "extraclasspathfilelist" nested elements, allowing users to optionally add external resources to the runtime classpath which will not be copied into the application bundle at build time. Removed some Java 1.4 requirements to allow building the sources under Java 1.3. Clarified the documentation.

26 July 2004 (version 1.2):

Added Ant property setters for "bundleid" and "developmentregion". Bundleid has no default, and is optional. Developmentregion defaults to "English", and is also optional. Fixed documentation on the website.

26 July 2004 (version 1.1):

Fixed several minor bugs, and improved BuildException messages. Jarfilesets and execfilesets now preserve directory structure when copying. Thanks to Trevor Harmon for pointing out bugs and enhancements.

25 July 2004 (version 1.0):

"execs" and "jars" can now be set using embedded FileSets or FileLists. Added a "verbose" flag, which currently sees limited use. Added "chmod" attribute, which can be used to point to a non-standard 'chmod' command (not normally needed!) Increased error checking. Hopefully, the code is now robust enough for widespread production use!

28 Dec 2003 (version 0.5):

Added setter for "execs" attribute. Added setter for "workingdirectory" attribute. Fixed missing setter for "arguments" attribute. Added alternate Java runtime parameter names for Mac OS X Java VM version 1.4.1. Included change submitted by Pierre-Luc Paour. Thanks also to Dante Briones and Graham Perks for pointing out bugs and enhancements.

12 October 2003 (Version 0.2:)

Added setter to properly support the "vmoptions" parameter. (Change submitted by Alok Saldanha)

Contact

Please contact Will Gilbert if you have bugs to report, patches to the code, ideas for enhancements, or any other suggestions! I can be reached at gilbert@informagen.com

Acknowledgments

Thanks to Dan Stowell for suggesting the "documenttype" task and supplying and example Info.plist file.

Thanks to Will Lowe for providing an example project which implemented "Apple Help Book" support for Java.

License

The Jar Bundler Ant Task is Copyright © 2002 - 2006, Seth J. Morabito. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

SourceForge.net Logo