Table of Contents

The ImageJ Eclipse Howto

A guide on how to include ImageJ into Eclipse and develop plugins using this IDE.

Author: Patrick Pirrotte (patrick@image-archive.org)

There are many different methods to include ImageJ into Eclipse to develop plugins. Four of them are described in this document. The recommended way is described in Method 1), while Method 4) is faster to setup for a quick hack.

Method 1: Setting up Eclipse to create and debug plugins for ImageJ

(on my computer the Java SDK library folder is located at C:\Program Files\Java\jdk1.6.0_02\lib)

Create a new plugin (or import your previously developed plugins).

import ij.IJ;
import ij.plugin.PlugIn;
 
public class TestPlugin_  implements PlugIn {
	public void run(String arg) {
		IJ.error("Hello world!");
	}
}

<project name="TESTPlugin_" default="" basedir=".">
    <description>
        TESTPlugin_ build file
    </description>
  <property name="src" location="src" />
  <property name="build" location="bin" />
  <property name="dist"  location="dist" />
 
	 <property name="pluginsDir"  location="$basedir/../../IJ/plugins/" />
 
  <property name="user.name" value="Patrick Pirrotte" />
<target name="main" depends="compress" description="Main target">
	<echo>
		Building the .jar file.
	</echo>
</target>
 <target name="compress" depends="" description="generate the distribution">
 	<jar jarfile="TESTPlugin_.jar">
 		<fileset dir="." includes="plugins.config" />
		<fileset dir="${build}" includes="**/*.*" />
 		<manifest>
 		 	 	      <attribute name="Built-By" value="${user.name}"/>
 		</manifest>
 	</jar>
    <copy file="TESTPlugin_.jar" toDir="${pluginsDir}" />
  </target>
</project>

Method 2: Importing the ImageJ source, using Eclipse's own build mechanism

Installing the source into Eclipse will allow you to quick-jump between ImageJ classes and your own plugins. It's really really useful to browse through the ImageJ API inside Eclipse.

Eclipse new project

Eclipse project name

Eclipse project settings 1

Eclipse project settings 2

Add source folder

Eclipse project settings 3

You can program your plugins which will be compiled against the ImageJ source code. To export your plugin go to File→Export and select JAR, export the jar to your ImageJ plugins folder.

Method 3: Importing the ImageJ source, using ImageJ build.xml, building with ant

(an alternative way proposed by Andy Weller)

[TODO: SCREENSHOTS WILL FOLLOW]

Method 4: Importing the ImageJ jar, no source browsing unless separate import of ImageJ source

[TODO: SCREENSHOTS WILL FOLLOW]

You could basically add the ij.jar file as a library to your plugin as seen above. From this point on you'll be able to develop ImageJ plugins. To enable ImageJ source code browsing you will have to attach the source code to the freshly imported ij.jar. (thanks to Aaron Ponti for this tip)

You should now be able to navigate through the ImageJ source code as if you had created a standalone project for ImageJ itself.

Any improvements or bugs? Send me your comments (patrick@image-archive.org)