2012. november 16., péntek

Java Alternatives on Ubuntu

This post shows how to install alternatives for all your JDK binaries in Ubuntu. Assume you have JDK 1.6.0_37 installed which contains the following binaries:
$ find /usr/lib/jvm/jdk1.6.0_37/bin -type f -executable | sort
/usr/lib/jvm/jdk1.6.0_37/bin/appletviewer
/usr/lib/jvm/jdk1.6.0_37/bin/apt
/usr/lib/jvm/jdk1.6.0_37/bin/ControlPanel
/usr/lib/jvm/jdk1.6.0_37/bin/extcheck
/usr/lib/jvm/jdk1.6.0_37/bin/HtmlConverter
/usr/lib/jvm/jdk1.6.0_37/bin/idlj
/usr/lib/jvm/jdk1.6.0_37/bin/jar
/usr/lib/jvm/jdk1.6.0_37/bin/jarsigner
/usr/lib/jvm/jdk1.6.0_37/bin/java
/usr/lib/jvm/jdk1.6.0_37/bin/javac
/usr/lib/jvm/jdk1.6.0_37/bin/javadoc
/usr/lib/jvm/jdk1.6.0_37/bin/javah
/usr/lib/jvm/jdk1.6.0_37/bin/javap
/usr/lib/jvm/jdk1.6.0_37/bin/javaws
/usr/lib/jvm/jdk1.6.0_37/bin/jconsole
/usr/lib/jvm/jdk1.6.0_37/bin/jcontrol
/usr/lib/jvm/jdk1.6.0_37/bin/jdb
/usr/lib/jvm/jdk1.6.0_37/bin/jhat
/usr/lib/jvm/jdk1.6.0_37/bin/jinfo
/usr/lib/jvm/jdk1.6.0_37/bin/jmap
/usr/lib/jvm/jdk1.6.0_37/bin/jps
/usr/lib/jvm/jdk1.6.0_37/bin/jrunscript
/usr/lib/jvm/jdk1.6.0_37/bin/jsadebugd
/usr/lib/jvm/jdk1.6.0_37/bin/jstack
/usr/lib/jvm/jdk1.6.0_37/bin/jstat
/usr/lib/jvm/jdk1.6.0_37/bin/jstatd
/usr/lib/jvm/jdk1.6.0_37/bin/jvisualvm
/usr/lib/jvm/jdk1.6.0_37/bin/keytool
/usr/lib/jvm/jdk1.6.0_37/bin/native2ascii
/usr/lib/jvm/jdk1.6.0_37/bin/orbd
/usr/lib/jvm/jdk1.6.0_37/bin/pack200
/usr/lib/jvm/jdk1.6.0_37/bin/policytool
/usr/lib/jvm/jdk1.6.0_37/bin/rmic
/usr/lib/jvm/jdk1.6.0_37/bin/rmid
/usr/lib/jvm/jdk1.6.0_37/bin/rmiregistry
/usr/lib/jvm/jdk1.6.0_37/bin/schemagen
/usr/lib/jvm/jdk1.6.0_37/bin/serialver
/usr/lib/jvm/jdk1.6.0_37/bin/servertool
/usr/lib/jvm/jdk1.6.0_37/bin/tnameserv
/usr/lib/jvm/jdk1.6.0_37/bin/unpack200
/usr/lib/jvm/jdk1.6.0_37/bin/wsgen
/usr/lib/jvm/jdk1.6.0_37/bin/wsimport
/usr/lib/jvm/jdk1.6.0_37/bin/xjc
You can do it manually for some of the important executables like java and javac:
sudo su
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_37/bin/java" 3000
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_37/bin/javac" 3000
...
...but there are a lot of necessary binaries, so you can just use the command below to create alternatives for all of the executables in one step:
for f in `find /usr/lib/jvm/jdk1.6.0_37/bin/ -executable -type f | sort`; do update-alternatives --install "/usr/bin/${f##*/}" "${f##*/}" "$f" 3000; done
Or if you just want to have the commands for copy-paste etc.:
for f in `find /usr/lib/jvm/jdk1.6.0_37/bin/ -executable -type f | sort`; do echo "update-alternatives --install \"/usr/bin/${f##*/}\" \"${f##*/}\" \"$f\" 3000"; done
Regards.

Nincsenek megjegyzések:

Megjegyzés küldése