Re: running fiji from Eclipse

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: running fiji from Eclipse

Curtis Rueden
Hi Aryeh,

Sorry for the long delay in reply.

> I finally decided to take the plunge and learn how to develop my
> python scripts in a real IDE.

This resource may be interesting to you:
  https://github.com/haesleinhuepf/run_jython_scripts_from_ide

> 1. When I first set it up, and added all of the jars and plugins to
> the Pydev-PYTHONPATH, I still could not run commands like
> IJ.run("3D OC Options", "long argument list.... The error was that
> 3D OC Options was not found.

Adding JAR files to the system classpath (which is what IDEs do by default)
is not enough. ImageJ1 wants the plugins.dir variable to be set to a
directory of JAR files with the plugins inside. Here is one way to work
around that:

https://github.com/imagej/example-legacy-plugin/blob/6d0eb4b7e3a289acc580a0da72e21821c624ef14/src/main/java/com/mycompany/imagej/Process_Pixels.java#L163-L187

The solution you posted is similar to that one.

> S0 my question is -- is this the best way to do this, or is there a
> way to run these commands  without launching the GUI. My instinct
> tells me that this may be related to running "headless", but I do not
> know enough about it.

The command you are using launches ImageJ1, which does not support headless
operation. You could pass the ImageJ.NO_SHOW flag to your ij.ImageJ
constructor. Or you could launch ImageJ2 instead. E.g.:

    public static void main(String... args) throws Exception {
        net.imagej.ImageJ ij = new net.imagej.ImageJ();
        ij.log().info(ij.plugin().getPlugins().size() + " plugins
available");
        // do more stuff...
        ij.context().dispose(); // quit
    }

> 2. Is there a better way to launch the GUI if I am using the Fiji
> distribution? My GUI is labeled ImageJ, not Fiji, but it seems to
> contain the entire FIji distribution.

In the above code snippet, calling ij.ui().showUI() will cause the main UI
to show. (Otherwise it won't.)

> 3. I have cases where my script beaks in the middle. In this case I
> had image windows left open that I could not close, until i figured
> out to kill multiple  instances of Jython that were running. Is there
> something that I should be doing to prevent Jython  processes from
> hanging around?

I am not sure. I usually just run "killall java" from the CLI on macOS when
dead processes accrue. Be careful though, because some IDEs on some
platforms will also be brought down by calls like that.

> 4. Is there a better way to add the required jars to the PYTHONPATH
> than to manually add them in the Properties as external libraries?

I suggest you read over Robert Haase's guide at:
  https://github.com/haesleinhuepf/run_jython_scripts_from_ide

It launches the Jython script via the ImageJ2 ScriptService, which will
include all the Java libraries from the system classpath. There should be
no need to manually install Jython, manually set PYTHONPATH, etc.

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? https://forum.image.sc/



On Sun, Jul 1, 2018 at 11:07 AM Aryeh Weiss <[hidden email]> wrote:

> I finally decided to take the plunge and learn how to develop my python
> scripts in a real IDE.
> So I muddled through a number of on-line resources and tutorials, and
> managed to install eclipse with pydev, and somehow I got it to work. I
> more or less used the following:
>
> http://wiki.cmci.info/documents/100825imagej_jython_eclipse
>
> https://www.rose-hulman.edu/class/csse/resources/Eclipse/eclipse-python-configuration.htm
>
> I have some questions about this.
>
> 1. When I first set it up, and added all of the jars and plugins to the
> Pydev-PYTHONPATH, I still could not run commands like IJ.run("3D OC
> Options", "long argument list....
> The error was that 3D OC Options was not found.
>
> However, after I added :
>
> from java.lang import System
> from ij import ImageJ
> pluginsDir2 = "/Applications/local/fiji/Fiji.app/plugins"
> System.setProperty("plugins.dir", pluginsDir2);
> ImageJ(); #this will launch ImageJ GUI
>
> which launches the GUI, then all was well with these commands.
>
> S0 my question is -- is this the best way to do this, or is there a way
> to run these commands  without launching the GUI. My instinct tells me
> that this may be related to running "headless", but I do not know enough
> about it.
>
> Aside -- is there a "direct" API way to use 3D OC Option, or the
> extended particle analyzer, or CLAHE, etc. Sometimes I find how to do it
> in the documentation, but other times I cannot find an API for some plugin.
>
> 2. Is there a better way to launch the GUI if I am using the Fiji
> distribution? My GUI is labeled ImageJ, not Fiji, but it seems to
> contain the entire FIji distribution.
>
> 3. I have cases where my script beaks in the middle. In this case I had
> image windows left open that I could not close, until i figured out to
> kill multiple  instances of Jython that were running. Is there something
> that I should be doing to prevent Jython  processes from hanging around?
>
> 4. Is there a better way to add the required jars to the PYTHONPATH
> than to manually add them in the Properties as external libraries?
>
> I apologize for the elementary nature of these questions -- there is lot
> of material on-line that no doubt covers this, but I am still a confused
> beginner with this. (For example, finding that I needed xerces was
> dauntng, until I found that the fiji jars directory has it...)
>
> Thanks in advance
> --aryeh
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html