Coming Up for Air

Oracle JDK and the Linux Alternatives System

For both work and fun, I run Linux. I’m also a Java guy, which poses some interesting challenges, as most Linux distributions have a long, sad tale regarding shipping Java. Things are a bit better, I guess, with OpenJDK, but I’ve always liked running the "real thing", which historically meant the Sun JDK, and now Oracle’s JDK (Note: current employment has no bearing on that choice ; ). If I were running an RPM-based distribution, I would be set. At the moment, though, I’m running Linux Mint, so I get to use the tarball.

Most of the time that works fine, but for reasons I don’t remember, OpenJDK was installed on my system, and now everything is using that (which is at Update 7, and not the recently released and more secure Update 11 that I want). I’d rather not monkey with changing PATH and all that, so I turned to the Linux alternatives system to handle things. Sadly, it wasn’t quite that easy, as alternatives needs to know about your alternatives, so before I could change things, I had to educate it, which turned out be easier than I feared. With Java 7 Update 11 installed in /opt/java/jdk1.7.0_11 and symlinked from /opt/java/latest, I had to do two things.

First, it seems the actual update script, update-java-alternatives, needs a .jinfo file in /usr/lib/jvm. Mine looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name=java-7-latest
alias=java-1.7-latest
priority=10
section=main

hl java /opt/java/latest/jre/bin/java
hl keytool /opt/java/latest/jre/bin/keytool
hl pack200 /opt/java/latest/jre/bin/pack200
hl rmid /opt/java/latest/jre/bin/rmid
hl rmiregistry /opt/java/latest/jre/bin/rmiregistry
hl unpack200 /opt/java/latest/jre/bin/unpack200
hl orbd /opt/java/latest/jre/bin/orbd
hl servertool /opt/java/latest/jre/bin/servertool
hl tnameserv /opt/java/latest/jre/bin/tnameserv
hl jexec /opt/java/latest/jre/lib/jexec
jre policytool /opt/java/latest/jre/bin/policytool
jdk appletviewer /opt/java/latest/bin/appletviewer
jdk extcheck /opt/java/latest/bin/extcheck
jdk idlj /opt/java/latest/bin/idlj
jdk jar /opt/java/latest/bin/jar
jdk jarsigner /opt/java/latest/bin/jarsigner
jdk javac /opt/java/latest/bin/javac
jdk javadoc /opt/java/latest/bin/javadoc
jdk javah /opt/java/latest/bin/javah
jdk javap /opt/java/latest/bin/javap
jdk jcmd /opt/java/latest/bin/jcmd
jdk jconsole /opt/java/latest/bin/jconsole
jdk jdb /opt/java/latest/bin/jdb
jdk jhat /opt/java/latest/bin/jhat
jdk jinfo /opt/java/latest/bin/jinfo
jdk jmap /opt/java/latest/bin/jmap
jdk jps /opt/java/latest/bin/jps
jdk jrunscript /opt/java/latest/bin/jrunscript
jdk jsadebugd /opt/java/latest/bin/jsadebugd
jdk jstack /opt/java/latest/bin/jstack
jdk jstat /opt/java/latest/bin/jstat
jdk jstatd /opt/java/latest/bin/jstatd
jdk native2ascii /opt/java/latest/bin/native2ascii
jdk rmic /opt/java/latest/bin/rmic
jdk schemagen /opt/java/latest/bin/schemagen
jdk serialver /opt/java/latest/bin/serialver
jdk wsgen /opt/java/latest/bin/wsgen
jdk wsimport /opt/java/latest/bin/wsimport
jdk xjc /opt/java/latest/bin/xjc
plugin mozilla-javaplugin.so /opt/java/latest/jre/lib/amd64/libnpjp2.so

Next, I needed to "install" my alternatives option. The script I used to do that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
update-alternatives --install /usr/bin/java java /opt/java/latest/jre/bin/java 10
update-alternatives --install /usr/bin/keytool keytool /opt/java/latest/jre/bin/keytool 10
update-alternatives --install /usr/bin/pack200 pack200 /opt/java/latest/jre/bin/pack200 10
update-alternatives --install /usr/bin/rmid rmid /opt/java/latest/jre/bin/rmid 10
update-alternatives --install /usr/bin/rmiregistry rmiregistry /opt/java/latest/jre/bin/rmiregistry 10
update-alternatives --install /usr/bin/unpack200 unpack200 /opt/java/latest/jre/bin/unpack200 10
update-alternatives --install /usr/bin/orbd orbd /opt/java/latest/jre/bin/orbd 10
update-alternatives --install /usr/bin/servertool servertool /opt/java/latest/jre/bin/servertool 10
update-alternatives --install /usr/bin/tnameserv tnameserv /opt/java/latest/jre/bin/tnameserv 10
update-alternatives --install /usr/bin/jexec jexec /opt/java/latest/jre/lib/jexec 10
update-alternatives --install /usr/bin/policytool policytool /opt/java/latest/jre/bin/policytool 10
update-alternatives --install /usr/bin/appletviewer appletviewer /opt/java/latest/bin/appletviewer 10
update-alternatives --install /usr/bin/extcheck extcheck /opt/java/latest/bin/extcheck 10
update-alternatives --install /usr/bin/idlj idlj /opt/java/latest/bin/idlj 10
update-alternatives --install /usr/bin/jar jar /opt/java/latest/bin/jar 10
update-alternatives --install /usr/bin/jarsigner jarsigner /opt/java/latest/bin/jarsigner 10
update-alternatives --install /usr/bin/javac javac /opt/java/latest/bin/javac 10
update-alternatives --install /usr/bin/javadoc javadoc /opt/java/latest/bin/javadoc 10
update-alternatives --install /usr/bin/javah javah /opt/java/latest/bin/javah 10
update-alternatives --install /usr/bin/javap javap /opt/java/latest/bin/javap 10
update-alternatives --install /usr/bin/jcmd jcmd /opt/java/latest/bin/jcmd 10
update-alternatives --install /usr/bin/jconsole jconsole /opt/java/latest/bin/jconsole 10
update-alternatives --install /usr/bin/jdb jdb /opt/java/latest/bin/jdb 10
update-alternatives --install /usr/bin/jhat jhat /opt/java/latest/bin/jhat 10
update-alternatives --install /usr/bin/jinfo jinfo /opt/java/latest/bin/jinfo 10
update-alternatives --install /usr/bin/jmap jmap /opt/java/latest/bin/jmap 10
update-alternatives --install /usr/bin/jps jps /opt/java/latest/bin/jps 10
update-alternatives --install /usr/bin/jrunscript jrunscript /opt/java/latest/bin/jrunscript 10
update-alternatives --install /usr/bin/jsadebugd jsadebugd /opt/java/latest/bin/jsadebugd 10
update-alternatives --install /usr/bin/jstack jstack /opt/java/latest/bin/jstack 10
update-alternatives --install /usr/bin/jstat jstat /opt/java/latest/bin/jstat 10
update-alternatives --install /usr/bin/jstatd jstatd /opt/java/latest/bin/jstatd 10
update-alternatives --install /usr/bin/native2ascii native2ascii /opt/java/latest/bin/native2ascii 10
update-alternatives --install /usr/bin/rmic rmic /opt/java/latest/bin/rmic 10
update-alternatives --install /usr/bin/schemagen schemagen /opt/java/latest/bin/schemagen 10
update-alternatives --install /usr/bin/serialver serialver /opt/java/latest/bin/serialver 10
update-alternatives --install /usr/bin/wsgen wsgen /opt/java/latest/bin/wsgen 10
update-alternatives --install /usr/bin/wsimport wsimport /opt/java/latest/bin/wsimport 10
update-alternatives --install /usr/bin/xjc xjc /opt/java/latest/bin/xjc 10
update-alternatives --install /usr/lib/mozilla/plugins/mozilla-javaplugin.so mozilla-javaplugin.so  /opt/java/latest/jre/lib/amd64/libnpjp2.so 10

Once that ran (Hint: i put that in a text file, which I ran via sudo bash foo), I was able to issue sudo update-java-alternatives -s java-1.7-latest and test my change:

1
2
3
4
java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Voila! Now all I need to do to update Java is install a new version and update the symlink. That was probably a lot more work than adding a PATH entry to point to my new JAVA_HOME, but it was also a lot more fun. :) I also have no idea, to be honest, if this is the "best" approach, or if everything I did is correct (especially the plugin part), but it works for now, and that was my goal. If I come across a more correct approach, I’ll likely revisit this. In the meantime, I can finally run the JDK I want, and that’s all I care about at the moment. :)

tags: Java

Quotes

Sample quote

Quote source