Login  Register

Re: How to use an own plugin or class in javascript?

Posted by dscho on Apr 28, 2010; 10:51am
URL: http://imagej.273.s1.nabble.com/How-to-use-an-own-plugin-or-class-in-javascript-tp3688475p3688476.html

Hi,

On Wed, 28 Apr 2010, Christian Moll wrote:

> I want to use one of my plugins from Javascript.
>
> importClass(ClassName)
>
> always returns this message:
>
> ReferenceError: "ClassName" is not defined. (<Unknown source>#4) in
> <Unknown source> at line number 4

The problem is that the script engine does not use ImageJ's class loader.
In Fiji, we use a specific Javascript engine, so we can set that class
loader explicitely:

http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/Javascript_/Javascript_Interpreter.java;h=3f6c658a1c2f9b67f218b0b33b59833e6defe3e5;hb=717e4875ba8c5e57f7c4427ce8872eb412adbe03#l25

Happily, it is relatively easy to convince the Javascript Engine of JDK6
to use ImageJ's class loader:

http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=commitdiff;h=e3bed9d7810443ff9033e25c6a12570fe8ebf672;hb=refs/heads/master

With this patch, it works here.

Ciao,
Johannes

P.S.: Note that in my experiments, I had to use something like
"importClass(Packages.Simulate_Color_Blindness);" to import the class,
i.e. the prefix "Packages." was crucial.