Developing ImageJ plug-ins using Xcode

A short guide for correctly configuring projects in Xcode (tested: 2.3 & 2.4)

I. Create a new project

  • Launch Xcode.
  • Create a new project: File -> New Project...
  • Choose 'Java Tool'. The name is important; it will be the same for the directory containing the compiled classes.
  • In the project window, two sets of preferences need to be modified, namely 'Project Information' (1) and 'Target Properties' (2):

II. Configuring the class output

When building the project, the generated classes must be copied to the 'ImageJ/plugins/plugin_name' directory for ImageJ to recognize them.
The easiest way of achieving this is by means of a Run Script:

  • In Xcode's Project menu, select 'New Build Phase -> New Run Script Build Phase'
  • Copy the line 'cp -r build/$CONFIGURATION/$PROJECT_NAME/ ~/user_path/ImageJ/plugins/$PROJECT_NAME/' into the Script field without the quotation marks. Replace 'user_path' with the respective path for your configuration.

Alternately, if your project is not located in '~/user_path/ImageJ/plugins/$PROJECT_NAME/':

  • Double-click 'ProjectName' (1) or select it and type Command-I
  • Change the 'Per-configuration Build Products Path' to your ImageJ plugins directory:

  • If the path contains spaces, make sure to add quotation marks, i.e., "Users/username/Desktop/ImageJ v x.xx/plugins"

III. Target properties

  • Double-click 'ProjectName' (2) in the 'Targets' submenu.
  • In the 'Search Paths' submenu, add the Project's directory to the 'Java Classes' search path (use the '+' icon):

  • In the 'Java Archive Settings' submenu, change the product type to 'Class Hierarchy':

IV. Importing ij.jar, and external classes/packages

  • Xcode needs access to the classes of ij.jar. Two approaches are possible for providing this:
    1. Import it into the project via drag & drop, or using the 'Action' drop-down menu -> Add -> Existing files...
    2. Add ij.jar to your system's Java extensions by copying it to '/Users/username/Library/Java/Extensions/ij.jar'
  • Any external classes/packages required for compilation must be copied to the project directory. For ImageJ, they also need to be copied to the plugin's respective directory. This is automatically done by Xcode for any classes/packages included in the project (via the same procedure as ij.jar):

V. ImageJ naming conventions

  • The main class in a project should end with an underscore, i.e., name_.java
  • Files can be renamed directly in Xcode by right-clicking their name in the project window and selecting 'Rename'