Debugging ImageJ Plugins in NetBeans

Downloading NetBeans and the ImageJ Source file
  1. Windows users should download and install the Java Development Kit (JDK) bundled with NetBeans from the Java SE Downloads page. Macintosh and Linux users should download the latest version of NetBeans for from netbeans.org.
  2. Download the latest ImageJ source code from rsb.info.nih.gov/ij/download/src/
  3. Unzip the ImageJ source. The folder "source" in the directory where you unzip this file is the ImageJ source folder
Setting Up ImageJ in NetBeans
Run NetBeans and open the File>New Project... dialog
  1. Choose Project
    • Select General and "Java Project with Existing Ant Script"
    • Click "Next >"
  2. Name and Location
    • Click "Browse..." next to the location text box.
    • Select and choose the source folder where the ImageJ build.xml file is located. At this point, NetBeans will fill in the four text boxes with the appropriate entries.
    • Click "Next >"
  3. Build and Run Actions
    • Click "Next >"
  4. Source Package Folders
    • Click "Add Folder..."
    • Select and choose the folder "...source\ij"
    • Click "Add Folder..."
    • Select and choose the folder "...source\plugins"
    • Click "Finish"
Building ImageJ with NetBeans
  1. Delete, or comment, line 12 (<exclude name="plugins/**" />) in source/build.xml
  2. Delete the file MacAdapter.java in source/plugins
  3. Go to the Build>Build Main Project (Ignore the red error messages in the ImageJ build output.)
  4. Go to the File> "ImageJ" Properties
  5. Select the Java Sources Classpath category
  6. Select ij[ij] in the as the Source Package Folder
  7. Click "Add JAR/Folder..."
  8. Select and choose the ij.jar file which NetBeans just built in the source directory
  9. Change the Source Package Folder to plugins[plugins]
  10. Click "Add JAR/Folder..."
  11. Select and choose the ij.jar file again
  12. Click "OK"
Compiling and Debugging Plugins
  1. Right click on the plugins folder and go to New>Java Class...
  2. Type in the name of your plugin
  3. Click "Finish"
  4. Write or paste your plugin into the Java Editor window.
  5. Go to Build>Compile "(The name of your plugin)"
  6. Click "Generate"
  7. In the ide-file-targets.xml file that was just created, change "${build.classes.dir}" to "plugins" in line 9
  8. Delete line 8 in the ide-file-targets.xml file
  9. Select your plugin from the ImageJ Project tree
  10. Go to Build>Compile "(The name of your plugin)"
  11. Go to Run>Debug Main Project
  12. Click "Set Output..."
  13. Click "OK"
  14. Go to Run>Debug Main Project
  15. Click "Generate"
  16. Go to Run>Debug Main Project (ImageJ will run. The plugin you created will be in the plugins menu)
  17. Go to Window>Debugging>Sources
  18. Check all the folders in the Sources tab
  19. Run you plugin from the ImageJ plugins menu. NetBeans will debug your plugin and stop at any specified breakpoints
For a list of NetBeans debugging commands go the NetBeans Debugger page.
For a more basic tutorial go to NetBeans Debugging Applications page.

More Tutorials

  1. Grant Harris at the Marine Biological Laboratory has written another ImageJ/NetBeans tutorial.
  2. Patrick Pirrotte has written a guide for Eclipse users.

[Return to ImageJ page]