Login  Register

Re: Javascript in Fiji does not work anymore

Posted by dscho on Jun 19, 2014; 2:44pm
URL: http://imagej.273.s1.nabble.com/Javascript-in-Fiji-does-not-work-anymore-tp5008314p5008318.html

Hi Christophe,

On Thu, 19 Jun 2014, Christophe Leterrier wrote:

> With the current up-to-date Fiji, my javascripts do not run anymore.
> When I try to launch them directly from the plugins menu, nothing
> happens. When I open them in the Fiji editor and run them, I get
> reference errors for basically every command :
>
> IJ.log("hello");
> fails
>
> var gd = new GenericDialog("test");
> fails too.

You need to call

importClass(Packages.ij.IJ);
importClass(Packages.ij.gui.GenericDialog);

before using the classes. I was unfortunately not aware of this behavior
in Fiji's Refresh_Javascripts plugin (which used to install the scripts
into the menu structure): apparently it auto-imported ImageJ 1.x' classes.

I was only aware that the script editor used to do that, therefore the
ImageJ2 script editor (which is now used in Fiji) supports auto-imports as
a deprecated feature.

Let's be very clear about this: auto-imports, as well as wildcard imports
are wrong. They are sloppy, and they *will* come back to bite you. What if
*some* plugin implemented an "IJ" class in the default package, i.e.
without a "package ..." statement? All of a sudden, you would be in a
royal mess of pain. I know, you would report it to the mailing list, and I
would fix it for you, but at some stage, I really have to question the use
of sloppy coding practices.

There is really no substitute for telling the computer *exactly* what to
do. Otherwise it will -- eventually, because computers are machines
designed to make your life as hard as possible -- break in the best of
funniest ways.

So: change your scripts to specify exactly which classes they want to use.
And then you're safer for all the future.

Ciao,
Johannes

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