X

Jeff Taylor's Weblog

  • Sun
    November 23, 2014

JAVA_HOME on Solaris 11

I recently asserted that it is not a good idea to set the JAVA_HOME
environment variable to /usr/java on Solaris 11. Instead, I'd recommend
something like this:

$ export JAVA_HOME=/usr/jdk/instances/jdk1.7.0

Why? Because it isn't clear where /usr/java will point to over time. Here are some details. Working with Solaris 11:

$ cat /etc/release
                            Oracle Solaris 11.2 SPARC
  Copyright (c) 1983, 2014, Oracle and/or its affiliates.  All rights reserved.
                             Assembled 23 June 2014

# pkg info entire | grep //
          FMRI: pkg://solaris/entire@0.5.11,5.11-0.175.2.0.0.42.0:20140624T193832Z



At first glance, it seems that /usr/java is a symbolic link to JDK 1.7:

$ ls -l /usr/java
lrwxrwxrwx   1 root     root          15 Aug 18 08:02 /usr/java -> jdk/jdk1.7.0_60



But on closer examination, it isn't a full JDK. Notice that jconsole, jps, etc are missing:

$ ls /usr/java/bin
ControlPanel  jcontrol      pack200       rmiregistry   tnameserv
java          keytool       policytool    servertool    unpack200
javaws        orbd          rmid          sparcv9



Installing the full JDK is easy:

$ sudo pkg install --accept jdk-7


And now the rest of the expected JDK programs are present:

$ ls /usr/java/bin

appletviewer  javah         jmap          native2ascii  servertool

extcheck      javap         jps           orbd          sparcv9

idlj          jcmd          jrunscript    pack200       tnameserv

jar           jconsole      jsadebugd     policytool    unpack200

jarsigner     jdb           jstack        rmic          wsgen

java          jdeps         jstat         rmid          wsimport

java-rmi.cgi  jhat          jstatd        rmiregistry   xjc

javac         jinfo         jvisualvm     schemagen

javadoc       jjs           keytool       serialver


Note that /usr/java is a symbolic link, to a second symbolic link, which links to a directory:

$ ls -ld /usr/java
lrwxrwxrwx   1 root     root          15 Aug 18 08:02 /usr/java -> jdk/jdk1.7.0_60

Following symbolic link 1:

$ ls -ld /usr/jdk/jdk1.7.0_60
lrwxrwxrwx   1 root     root          18 Aug 18 08:02 /usr/jdk/jdk1.7.0_60 -> instances/jdk1.7.0


Following symbolic link 2:

$ ls -ld /usr/jdk/instances/jdk1.7.0/
drwxr-xr-x   6 root     bin            7 Aug 18 08:02 /usr/jdk/instances/jdk1.7.0/



But if you install jdk-8, the links change:

$ ls -ld /usr/java

lrwxrwxrwx   1 root     root          15 Nov 21 13:08 /usr/java -> jdk/jdk1.8.0_20


$ ls -ld /usr/jdk/jdk1.8.0_20

lrwxrwxrwx   1 root     root          18 Nov 21 13:08 /usr/jdk/jdk1.8.0_20 -> instances/jdk1.8.0

So if your JAVA_HOME was set to /usr/java, your application would start using JDK-8.

$ export JAVA_HOME=/usr/java

$ $JAVA_HOME/bin/java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

It is interesting that, in contrast, when you install JDK-6 and JDK-7 is already installed, the /usr/java links will continue to point to the JDK with the higher major version.

My advice is that if your application is certified with JDK-7, and you'd like
the users to automatically pick up the newest bug fixes and security
updates, this is the safest bet.

$ export JAVA_HOME=/usr/jdk/instances/jdk1.7.0


Hope this helps.

Join the discussion

Comments ( 2 )
  • Alan Coopersmith Monday, November 24, 2014

    By default, the link will point to the highest version number of Java installed via the IPS packaging system, but sites which want a different default can change it via the 'pkg set-mediator' command as shown in https://docs.oracle.com/cd/E36784_01/html/E36802/gnztu.html .


  • Jeff Tuesday, November 25, 2014

    Hi Alan,

    Thanks for the pointer to 'pkg set-mediator'

    It looks like the functionality is very similar to "/usr/sbin/alternatives --config java" and "/usr/sbin/update-alternatives --config java" available in some Linux distributions such as Red Hat and Ubuntu.

    I like that Solaris sets the entire Java default bundle in one shot. With the Linux alternatives method, there are too many ways to mix and match, for example, default java from 1.7 but default javac from 1.8. I wonder how many installations benefit from that much flexibility vs. how many installations are unintentionally misconfigured.

    Jeff


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.