You are here

Java on DICE

Printer-friendly versionPrinter-friendly version

Supported Versions

We support multiple versions and distribution of Java (both the JVM runtime ("JRE") and development tools "JDK"). Here's a summary of the versions to be found on DICE:

DICE SL7 and Virtual DICE SL7
Version Distribution Location Notes
1.7.0 OpenJDK /usr/lib/jvm/java-1.7.0-openjdk.x86_64/
1.8.0 Sun/Oracle /usr/lib/jvm/java-1.8.0-sun/ available on request
1.8.0 OpenJDK /usr/lib/jvm/java-1.8.0-openjdk.x86_64/ available on request
10.0.x Oracle /usr/lib/jvm/java-10-oracle/ optional (see below)

The default Java version on DICE is shown above but it is subject to change over time (though typically only between semesters). However, differences between distributions are nowadays negligible for most users, and specialist requirements mean it's better for users to specify defaults individually. There are different ways to do this, depending on the way your JVM is invoked.

Checking the default version

The default java binaries are normally specified by the "alternatives" system, defined by linking /usr/bin/<appname> to each of the binaries in a given JDK directory. Note that java (provided by the JRE) and javac/javadoc/etc (provided by the JDK) can therefore be different! Your own environment including the PATH variable can override what's been set by alternatives, however.

You can discover the default version by PATH simply by executing:

$ java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (rhel-2.5.4.0.el6_6-x86_64 u75-b13)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)

$ javac -version
javac 1.7.0_75

You can check if this is the version controlled by alternatives by running:

$ which java
/usr/bin/java

(any other result but /usr/bin/java suggests you have already overridden the machine's default version).

Unfortunately the latter doesn't tell you the distribution of javac, only its version. Fortunately this can be inferred from where it's installed, using with the following, e.g.:

$ which javac | xargs readlink -f
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/bin/javac

New for 2018: Using Java 10

Java 10 is installed on most DICE machines but because it differs in a few ways from older versions it is not used automatically. You can call its binaries directly from its installation directory:

/usr/lib/jvm/java-10-oracle/bin/

but if you'd rather use it by default you can use the module system to apply it as your default JDK/JRE:

  (before...)
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13) 
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

  (find out what optional version of java is available...)
$ module avail java
java/10.0.2

  (make the newest version of Java your default:)
$ module add java
(you can also specify the version directly, i.e. module add java/10.0.2)

$ java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

echo $JAVA_HOME
/usr/lib/jvm/java-10-oracle-10.0.2/

This change persists only so long as your terminal is open, unless you add the module command to a shell startup script. You can also remove this from your terminal at any time with module rm java.

Choosing a version

The suggested mechanism to override the default version by PATH would be to create a symbolic link in your ~/bin/ directory for each of the applications whose versions you wish to change, e.g. java or javac. Alternatively you could set aliases in your bash config, if you're mainly interested in interactive use. You could also prepend the bin JDK subdirectory to your PATH if you are likely to need alternative versions of some of the other applications bundled with Java (e.g. wsgen or javadoc).

Choosing a JVM directory

It's recommended that you avoid the precisely-versioned links (e.g. "java-1.7.0-openjdk-1.7.0.55.x86_64") unless you are testing a specific build. Automatic updates will mean that these directories will change regularly. In general, if you want to set a specific distribution or version of Java, you should use the most general link available in /usr/lib/jvm/, e.g.:

  • Version 1.8, any distribution: /usr/lib/jvm/java-1.8.0
  • Latest Sun/Oracle version: /usr/lib/jvm/java-sun
  • OpenJDK, version 1.7: /usr/lib/jvm/java-1.7.0-openjdk.x86_64 (on 64-bit systems)

...and so on.

The JAVA_HOME variable

This is not set by default, but users can add this to their ~/.brc to influence certain pieces of software. It can however be confusing to have this in conflict with the default version by PATH so it's recommended that you only set this when required, or tie them together somehow, e.g.

  within .brc:
export JAVA_HOME="/usr/lib/jvm/java-1.7.0-sun/"
alias java="$JAVA_HOME/jre/bin/java"
alias javac="$JAVA_HOME/bin/javac"
alias javadoc="$JAVA_HOME/bin/javadoc"
[...]

remembering that aliases only apply to interactive shells (i.e. this will not apply to scripts you've written, with certain exceptions). If you'd like to set the default for the duration of a script, you could also do so with $PATH:

#!/bin/sh
export JAVA_HOME="/usr/lib/jvm/java-1.7.0-sun/"
export PATH="$JAVA_HOME/bin:$PATH"
[...]

Per-machine defaults

Support can also change the default version of Java on a per-machine basis by manipulating the alternatives system. In general we would not do this on multi-user or lab hosts, and we don't really recommend it anywhere else (it's difficult to prevent software updates from overriding this from time to time) so we'd advise you to use other means to do this. However if you have a special requirement (or you think the default is set in error) you can contact us in the usual way.

Java 1.8 and Apache Ant

There appears to be an incompatibility between installed versions of Ant and Sun/Oracle Java 1.8 on our SL6 systems. This means that if you use JAVA_HOME to specify a default version of Java, ant will fail with an error about a missing tools.jar. This fix for this is simple, set both JAVA_HOME and ANT_HOME before use in your script or shell:

export JAVA_HOME="/usr/lib/jvm/java-sun/" # defaults to latest Sun/Oracle version of Java
export ANT_HOME="/usr/share/ant/" # this is a notional Ant home directory, you could use your own self-installed version if you'd prefer
ant [arguments...]

Java Plugin for Web Browsers

tl;dr: Java Applets are no longer supported on DICE: contact us if you need some workaround or specific solution for your applet.

The Java "applet" plugin for web browsers used to be a standard part of the DICE environment, but the popularity of the applet in the wider web has declined significantly, while the security issues associated with applets have become more apparent. Applet support has been officially deprecated by Oracle, support has been long since removed from all major browsers, and as of August 2018 has been removed from Firefox "ESR" release, as carried on DICE.

If you still require the ability to run Java applets you can make use of the legacy appletviewer provided by an older (<= 1.8.x) Java release, and if this workaround doesn't work for you please contact support who can try to find out if there's some other way to do what you want, but can not guarantee any such code will continue to run on our - or any other - modern environment.

Installing libraries

DICE does not provide an extensive Java package library, though it does carry a few popular packages and dependencies for mainstream software. The wider expectation seems to be that software packages will include their own library files where appropriate. Typically this is done by adding jar files to a library directory, and adding these files individually to your software's CLASSPATH, and advice on managing the Java classpath can be found from reputable sources online.

If you have a specific requirement for a Java library to be provided on all DICE machines you may request this in the usual way.

Last reviewed: 
24/07/2018

System Status

Home dirs (AFS)
Network
Mail
Other services
Scheduled downtime

Choose a topic