Login  Register

Re: How to test plugin?

Posted by Senseney, Justin (NIH/CIT) [E] on Jul 15, 2009; 4:49pm
URL: http://imagej.273.s1.nabble.com/How-to-uninstall-macros-tp3691772p3691776.html

Vivian,

Dscho's solution is a good general solution, but there's another way that I've found works a lot better when developing ImageJ plugins in Eclipse.  This only works reliably with the newer versions of Eclipse (Europa, Ganymede, etc). Try these steps:

1) Create a new Java project in Eclipse called "ImageJ" and put the ij.jar and IJ_Prefs.txt from your ImageJ install into this new project's working directory.  

2) Change the default output folder of your ImageJ project to "plugins", create a "src" folder to hold all your plugins in that same dialog box.

3) Refresh the project (so you can see the jars), then add ij.jar to the project's classpath.

4) Make a dummy plugin (implements PlugIn, has run(String) method)

5) Finally, in the Run configurations... tab set your main class to ij.ImageJ

When you run this configuration, your dummy_plugin appears in ImageJ's list of plugins.  When you make changes to this plugin, your changes are reflected as soon as you restart ImageJ.  It's a little work to set up, but this is the most efficient way I've found to work on ImageJ plugins.  You can even attach the ImageJ src to the jar and use those files to debug w/ line references.

-Justin

-----Original Message-----
From: Johannes Schindelin [mailto:[hidden email]]
Sent: Tuesday, July 14, 2009 6:42 AM
To: List IMAGEJ
Subject: Re: How to test plugin?

Hi Vivian,

On Tue, 14 Jul 2009, Vivian Yong wrote:

> I tried to write a testing plugin based on the ImageJ tutorial. I can
> test it after I put the plugin file in the ImageJ plugin folder. I just
> wonder how can I test run it in Eclipse? Also, I would like to see the
> output on the system for debugging purpose by using
> System.out.print("..."); before the plugin be deployed to ImageJ, is
> that possible and how?

In a plugin I recently reviewed, I saw this gem:

        public static void main(String[] args) {
                try {
                        System.getProperties().list(System.err);
               System.setProperty("plugins.dir", args[0]);
                        new ImageJ();
                        IJ.run("This Plugin", "argument=value argument=value");
                } catch (Exception ex) {
                        e.printStackTrace();
        }
        }

You specify the plugin class as main class, and pass the main() method the
path to the directory containing the corresponding .class file.  Before
constructing ImageJ(), you can output anything to System.out (or
System.err).  Of course, you need to adjust the parameters of IJ.run()
appropriately.

Hth,
Dscho