Thursday, October 19, 2017

ImageJ and ECMAScript 6


With the last update of ImageJ 1.51r, it is possible to use Java 9 and its new JavaScript engine Nashorn with ECMAScript 6 functionalities.... and that's a great news!! See how to do that...


1. Configuration of JVM

Go to the Oracle Java Downloads page [Link], click on the Download button of  the JRE — Java Runtime Environment — and select the file corresponding to your Operating System and your architecture (64-bit).

2. Configuration of ImageJ

Note: This section only describes the procedure for Linux computers.

In your ImageJ folder, there is a file named run , open it with your favourite text editor, then modify the line beginning with "java..." by:

mypath/where/is/jre9/bin/java -Dnashorn.args=--language=es6 -Xmx2048m -cp ij.jar ij.ImageJ

First, you have to give the path of java9,

mypath/where/is/jre9/bin/java

... then for activating ECMAScript 6 for Java, you must add the option:

-Dnashorn.args=--language=es6

Finally, you could allocate more memory with the option -Xmx (expressed in bytes):

-Xmx2048m 

3. Check versions

Now, run ImageJ with the modified script run and look at the Plugins>Utilities>ImageJ Properties [cf: previous post] to see if you have java9.x as java.version.
Morever,we have to check the JavaScript version..., go to Plugins>New> JavaScript, and paste the following lines...

let i=3;
IJ.log(`${i}`);
const foo = x => x+3;
IJ.log(foo(4));

Run this script (Ctrl + R).

If you see in the Log window, the numbers 3 and 7. Congratulations!!, you have access to ECMAScript 6 (or ES6 or ES2015) functionalities ... and that's a really great news. I will explain this in the next posts...

Thank you for reading...


4. Other crazybiocomputing posts

Further readings are available in ...
  • Programming in JavaScript Series  [Link]
  • JavaScript/ECMAScript TOC [Link]



No comments:

Post a Comment