Mint 12 (/Ubuntu): Set up Java alternatives

Saturday, February 18th, 2012 | Java, Linux, Tech-savvy

Your modern Linux distro will provide you with a more or less decent Java setup by default. Mint 12 comes with a Sun JDK 1.6.0.26 pre-installed. To switch between installed versions of your Java runtime use the

update-java-alternatives --list

command to list installed alternatives and

update-java-alternatives --set alternative

to switch them. If you still want to have different versions of the JDK you can always download them manually, untar and use them directly. So far so good.

I wanted to be able to switch my downloaded JDKs as easy as the pre-installed ones, so I was looking for a way to add my JDKs to my system’s repository. So here is how it’s done (it’s basically a copy of a nice post I found, I just wanted to spread the knowledge) – it’s a bit painful but made me feel quite good when I was done :)

Java alternatives can be found in /usr/lib/jvm. Each installation has its own folder and a (hidden) .jinfo file. It’s not enough to simply symlink your JDK here, you have to provide a .jinfo file.

nick@silentbox /usr/lib/jvm $ ls -a
.  ..  java-6-sun  java-6-sun-1.6.0.26  .java-6-sun.jinfo

What you need to provide in order to have a new alternative is a JDK (obviously) and a corresponding .jinfo file. Just copy one of the existing .jinfo files and change it according to your needs. In case you have no such file, here is a sample content:

name=java-6-sun-1.6.0.26
alias=java-6-sun
priority=63

jre ControlPanel /usr/lib/jvm/java-6-sun/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-6-sun/jre/bin/java
jre java_vm /usr/lib/jvm/java-6-sun/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-6-sun/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-6-sun/jre/bin/jcontrol
jre keytool /usr/lib/jvm/java-6-sun/jre/bin/keytool
jre pack200 /usr/lib/jvm/java-6-sun/jre/bin/pack200
jre policytool /usr/lib/jvm/java-6-sun/jre/bin/policytool
jre rmid /usr/lib/jvm/java-6-sun/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-6-sun/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/java-6-sun/jre/bin/unpack200
jre orbd /usr/lib/jvm/java-6-sun/jre/bin/orbd
jre servertool /usr/lib/jvm/java-6-sun/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-6-sun/jre/bin/tnameserv
jre jexec /usr/lib/jvm/java-6-sun/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/java-6-sun/bin/appletviewer
jdk apt /usr/lib/jvm/java-6-sun/bin/apt
jdk extcheck /usr/lib/jvm/java-6-sun/bin/extcheck
jdk HtmlConverter /usr/lib/jvm/java-6-sun/bin/HtmlConverter
jdk idlj /usr/lib/jvm/java-6-sun/bin/idlj
jdk jar /usr/lib/jvm/java-6-sun/bin/jar
jdk jarsigner /usr/lib/jvm/java-6-sun/bin/jarsigner
jdk javac /usr/lib/jvm/java-6-sun/bin/javac
jdk javadoc /usr/lib/jvm/java-6-sun/bin/javadoc
jdk javah /usr/lib/jvm/java-6-sun/bin/javah
jdk javap /usr/lib/jvm/java-6-sun/bin/javap
jdk jconsole /usr/lib/jvm/java-6-sun/bin/jconsole
jdk jdb /usr/lib/jvm/java-6-sun/bin/jdb
jdk jhat /usr/lib/jvm/java-6-sun/bin/jhat
jdk jinfo /usr/lib/jvm/java-6-sun/bin/jinfo
jdk jmap /usr/lib/jvm/java-6-sun/bin/jmap
jdk jps /usr/lib/jvm/java-6-sun/bin/jps
jdk jrunscript /usr/lib/jvm/java-6-sun/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-6-sun/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-6-sun/bin/jstack
jdk jstat /usr/lib/jvm/java-6-sun/bin/jstat
jdk jstatd /usr/lib/jvm/java-6-sun/bin/jstatd
jdk native2ascii /usr/lib/jvm/java-6-sun/bin/native2ascii
jdk rmic /usr/lib/jvm/java-6-sun/bin/rmic
jdk schemagen /usr/lib/jvm/java-6-sun/bin/schemagen
jdk serialver /usr/lib/jvm/java-6-sun/bin/serialver
jdk wsgen /usr/lib/jvm/java-6-sun/bin/wsgen
jdk wsimport /usr/lib/jvm/java-6-sun/bin/wsimport
jdk xjc /usr/lib/jvm/java-6-sun/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin firefox-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin iceape-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin iceweasel-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin midbrowser-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin xulrunner-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so

Change the name and alias, ignore the prio and change all directories accordingly.

I really thought I was done when I edited the .jinfo file, yet update-java-alternatives did not work yet. It’s a pain, but you have to register the stuff you just edited before you can use it. Let’s say the file we need to register is .jdk1.6.31.jinfo an the corresponding JDK is located in /opt/jdk1.6.31/

nick@silentbox /usr/lib/jvm $ cat .jdk1.6.31.jinfo | grep -E '^(jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install
nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30
nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30

After that update-java-alternatives --list should list your just installed alternative and you should be able to switch it natively like any other JDK the system provided out of the box.

Thanks again maciek for teaching me this in the first place :)

Tags: ,

2 Comments to Mint 12 (/Ubuntu): Set up Java alternatives

Jerry Preissler
22. February 2012

Thanks, that has been very helpful.

Rudy
2. April 2013

Need to update grep to include ‘hl’ for oracles 1.7.0.

grep -E ‘^(hl|jre|jdk)’

Leave a comment

Search

Categories