Developing ImageJ Plugins in Eclipse

Kimo Johnson

06 October 2006

Eclipse is a great Java development environment. Its refactoring, continuous compilation, and import management features really improve my productivity and make Java development far less painful. The downside, if you've never used it before, is having to learn a new IDE and having to search for where in the IDE to specify certain settings. Here is a small guide on how to configure Eclipse for ImageJ plugin development.

The first step is to download ImageJ and Eclipse. I won’t go through the details of setting up a new project, since there are numerous other Eclipse tutorials that cover that. The only point to note is to choose the “Create separate source and output folders” option in the second pane of the wizard and rename the “Default output folder” from “bin” to “plugins” in the third pane of the wizard.

Now go to the ImageJ directory and copy ij.jar into your project directory in Eclipse. This step simplifies the build script (described in my next blog), but isn’t necessary otherwise.

In your project directory, also create a directory called “externals” for external jar files. My plugin requires JAMA for linear algebra routines and JAI ImageIO for converting from ImageJ objects to Java Advanced Imaging (JAI) objects. One thing to note is that JAI is built into Mac OS X Tiger (10.4), but is an additional download for other platforms and earlier versions of OS X. Download any external jar files and put them in the “externals” directory in your project directory.

Now in Eclipse, we can add the external jars to the project by going to the project “Properties” and clicking the “Libraries” tab. There’s a button to add external jars and you should add ij.jar as well as your external jars. Note that I don’t store ij.jar in the externals folder. This decision is also related to my build script since ij.jar does not need to be bundled into your plugin, while other external jars do.

At this point, you should be ready to write your plugin without compilation problems. Note that Eclipse compiles in the background and will notify you of errors while you are programming. If there are no errors, then it’s ready to run. But before we run it, we need to configure Eclipse to launch ImageJ.

Under the “Run” menu, choose “Run…”. This choice brings up the Run configuration manager. We will create a new Java Application Run configuration called ImageJ by clicking the New button (looks like a file with a plus in the upper left of the window). Here are the appropriate settings:

Name: ImageJ 
Main tab: 
Project: Your ImageJ plugin project name
Main class: ij.ImageJ
Arguments tab:
VM arguments: -Xms256m -Xmx512m 

Note that for the plugins.dir settings, you don’t put “plugins” in the path. That’s assumed by ImageJ and that’s the reason we named our build directory “plugins”.

At this point, you should be able to Run ImageJ from within Eclipse and see your plugin in the “Plugins” menu.

Update (9/2008)

The VM arguments have been updated with corrections suggested by Stephan S.

Update (7/2012)

The plugins and macros directory arguments have been updated with corrections suggested by J. Mateos.