Developing ImageJ plug-ins using Xcode 3

A short guide for configuring projects in Xcode 3 (older versions)

I. Create a new project

  • Launch Xcode.
  • Create a new project: File -> New Project...
  • Choose 'Java Tool'. The name is important; project directories and build paths depend on it.
  • In Xcode 3, the build process is handled via Ant; compilation/building steps are defined in the build.xml file.

II. Modifying build.xml

The default structure of build.xml performs more steps than initially needed to compile a plugin for ImageJ.

Only the following phases are essential:

  • Link to external classes/packages (i.e., to ij.jar).
  • Compile source files.
  • Copy classes to the ImageJ/plugins/plugin_name directory.

Four directories will be created in the project directory: build, bin, ressources, src.
The links to the dist, jars, and lib directories can be removed.

An according build.xml file is available here.
Only the ImageJ path in the <property name="imagej" location="/Users/../ImageJ"/> tag needs to be modified.

<?xml version="1.0" encoding="UTF-8"?>

<project name="tutorial" default="javadoc" basedir=".">

<property name="src" location="src"/> <!-- java source folder -->

<property name="bin" location="bin"/> <!-- intermediate build products -->

<property name="dist" location="dist"/> <!-- build product location -->

<property name="javadoc" location="javadoc"/> <!-- javadoc location -->

<property name="resources" location="resources"/> <!-- location of additional resources (images etc.) -->

<property name="imagej" location="/Users/../ImageJ"/> <!-- ImageJ folder -->

<property name="dest" location="${imagej}/plugins/${}"/> <!-- destination folder -->

<property name="compile.debug" value="true"/>

<!-- References to external libraries -->

<path id="lib.path">

<pathelement path="${imagej}/ij.jar"/>


<!-- Initialization target, for any prelimary setup needed to build -->

<target name="init" description="Preparation">

<mkdir dir="${src}"/>


<!-- Compile .java files inside the $src directory -->

<target name="compile" depends="init" description="Compile code">

<mkdir dir="${bin}"/>

<javac deprecation="on" srcdir="${src}" destdir="${bin}"

  source="1.5" target="1.5"


  classpathref="lib.path" debug="${compile.debug}">



<!-- Build JAR file, include resources -->

<target name="jar" depends="compile" description="Build jar">

<mkdir dir="${dist}"/>

<jar destfile="${dist}/${}_.jar">

<fileset dir="${bin}"/>

<zipfileset dir="${resources}" prefix="resources"/>

<zipfileset dir="." includes="plugins.config"/> <!-- Required to configure the "Plugins" menu in ImageJ-->



<!-- Copy JAR file to plugins directory -->

<target name="installJAR" depends="jar" description="Copy JAR file to plugins directory">

<copy toDir="${imagej}/plugins">

<fileset dir="${dist}">

<include name="*.jar"/>




<!-- Copy class folder to plugins directory -->

<target name="installClass" depends="compile" description="Copy classes plugins/project directory">

<mkdir dir="${dest}"/>

<copy toDir="${dest}">

<fileset dir="${dist}">

<exclude name="*.jar"/>




<!-- Generate documentation -->

<target name="javadoc" depends="installJAR" description="Create Javadoc">

<mkdir dir="${javadoc}"/>

<javadoc destdir="${javadoc}" classpathref="lib.path">

<fileset dir="${src}/">

<include name="*.java"/> 




<!-- Directories deleted when cleaning -->

<target name="clean" description="Remove build and dist directories">

<delete dir="${bin}"/>

<delete dir="${dist}"/>

<delete dir="${javadoc}"/>



III. ImageJ naming conventions

  • Executable classes in a project should end with an underscore, i.e., "".
  • Files cannot be renamed from Xcode 3, but changes in the Finder are reflected.

IV. Selecting the build path

  • In this example, several build paths are available, the default being "javadoc", which can be changed in the second line of the build file.

V. Documentation

  • The documentation requires comments to be in the javadoc format.

VI. Example

  • A project with the files from this tutorial is available here.