Building OS X Install Packages with Ant

Lets say you want to create a nice installer for your OS X application that looks something like this -

Lets also say you want to it completely automated so you can do it with a simple one line command OR make it part of an integration build process.

Using XCode’s PackageMaker tool and ant, its pretty simple to create a build.xml that automatically creates a package for you.  In fact, its even easier for you because I’ve already created a sample project that does this!

Requirements

You will need the following tools

This article assumes you have are familiar with Apache ant.

Quick Start

Download the AntPackageMaker sample project -

  1. Open a teminal
  2. cd into its directory
  3. Type ‘ant’ 

This will create a package installer for the world famous TextEdit application in the directory ‘pkg’.  You can open this directory in Finder and double click ‘TextEdit.pkg’ to see the results!  Move on to the next section for customizing AntPackageMaker for your own project.

AntPackageMaker Project Overview

This sample project contains a template package to use for creating a customized package, a sample application (TextEdit.app) and ant files necesary to create the package.  

Files and Directories

  • build.xml – The ant build file
  • bundle/ - Put your application bundle here – i.e. MyApp.app.  Don’t forget to remove TextEdit.app!
  • pkg-src/ - The package template files
  • pkg.properties - The ant properties files for building the package

Customizing

Here’s what you need to do to customize this project for own app. 

  1. Copy your application into the ‘bundle’ directory. Make sure you remove TextEdit.app
  2. Customize the files License.rtf and Welcome.rtf in the ‘pkg-src’ directory.
  3. Change the background.gif image in the ‘pkg-src’ directory and, yes, it has to be a GIF.  
    TIP – Make sure you save it with transparency and set the transparency matte to #EEEEE
  4. Open pkg.properties in a text editor and change the values as necessary.  You could even use TextEdit – just make sure to keep the formatting pain text!

Here’s a look at pkg.properties – all you need to change is ‘pkg.name’ to the name of your application.

## Package Properties

# Application name - here we're bundling TextEdit
pkg.name=TextEdit

# Location for the application bundle, i.e. TextEdit
# This sample project has TextEdit in the local 'bundle' directory
pkg.bundle=${basedir}/bundle

# Directory where the package template lives
pkg.src.dir=${basedir}/pkg-src

# Directory where we will create the package
pkg.dir=${basedir}/pkg

# The actual package
pkg=${pkg.dir}/${pkg.name}.pkg

# The package Info.plist - gets autogenerated
pkg.info=${pkg.src.dir}/Info.plist

# The package Info.plist template to use
pkg.info.template=${pkg.info}.template

# The package Description.plist - gets autogenerated
pkg.description=${pkg.src.dir}/Description.plist

# The package Description.plist template to use
pkg.description.template=${pkg.info}.template

Usage

Feel free to use this however you wish! If it helps you out, I’d love to hear about it.

Leave a Reply