Friday, March 18, 2016

Configuration: Java and Linux



Before writing JavaScript small programs in Linux, you have to check the Java version used by ImageJ because of a bug with the latest Java packages...


In Linux, there are two different packages:
  • An open-source version: OpenJDK  
  • A proprietary: Oracle's Java. 
By default, most of the Linux distributions have installed the OpenJDK and the latest versions (version 1.8.xx) do not work well with ImageJ. Indeed, when you run a JavaScript program in ImageJ, no error message are displayed in the Log window, so it is very difficult (impossible?) to debug your code.

Note: When you read these lines, I am using ImageJ version 1.50f with Ubuntu 14.04 LTS. This bug might be solved in more recent updates.

1. Configuration of Java

If you have downloaded in the ImageJ website,  ImageJ + Java 1.6 or ImageJ + Java 1.8, there is no problem because these distributions are packaged with an Oracle's Java Runtime Environment (jre). However, if you just download the Platform Independent package of ImageJ to save space on your hard disk, you have to checked your pre-installed Java version.
1.1. How to check my Java version in ImageJ?
Run ImageJ and go to Plugins > Utilities > ImageJ Properties to open a popup window entitled Properties (Fig. 1)...


Fig.1: Properties window displaying ImageJ configuration. The first two lines describe the Java software (version and manufacturer) and the line java.vm.name in the end of the listing (not shown in this snapshot) indicates what kind of distribution you are using, here, an OpenJDK 64-Bit Server VM.

Now, look at the first line java.version and java.vm.name to get the version and Java distribution.
1.2. How to check my Java version in a shell?
Open a shell (or terminal) and type the following command:

java -version

If you have an OpenJDK, this kind of message is displayed:

java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

... or this one if you have an Oracle's (HotSpot) ...

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

1.3. How to check my Java version in JavaScript 
If you know how to write a script in ImageJ, just run these two lines:

IJ.log(System.getProperty("java.version"));
IJ.log(System.getProperty("java.vm.name"));

Update [Oct. 2017]: With the version ImageJ 1.51r, it is possible to use Java9 and a JavaScript Engine supporting ECMAScript 2015+ functionalities.

Hope that helps!!




2. Other crazybiocomputing posts

Further readings are available in ...
  • Programming in JavaScript Series  [Link]
  • Image Processing TOC [Link]



No comments:

Post a Comment