I've just recently upgraded to Fedora 16 (from fedora 12), and have read/been told that instead of setting up different JDKs by using a simple symlink and setting my $PATH to that symlink, I should be using the alternatives tool.
What I don't understand is how alternatives is better for managing your jdk, when it seems you would have to run: alternatives --config not only for 'java' but also all the supporting tools (javac, javaws, jstack, etc). This seems miserable compared to:
(Assume $PATH=/opt/local/java/current/bin:...)
rm /opt/local/java/current
ln -s /path/to/unpacked/jdkX /opt/local/java/current
So my question is:
Why do I hear alternatives is the proper way to manage java tools in newer versions of Fedora when it seems much more cumbersome to fully switch JDK's? Have I just been told poor information, or am I missing something important about alternatives?
(NOTE: Feel free to be brutal if alternatives is clearly better in some way. I'm aware I'm largely ignorant about the tool)
If you know you just need to swap out one or two tools (ex: java and javac), alternatives seems like the way to go, as it is the intended way to manage application versions.
However, if you are using multiple development tools that may require a JAVA_HOME or JDK_HOME value set, or if you don't know which of the jdk utilities the tool(s) may call, it seems exporting your jdk path to $JAVA_HOME, and prepending it to $PATH is a simpler way to go. It may not be the "correct" way, but it's quicker to switch between java versions, and more transparent as you know all your jdk utilities will be pointed at the same version.
Symlink your current jdk
ln -s /opt/local/java/jdk_1.X_XX current
In ~/.bash_profile OR ~/.bashrc add
JAVA_HOME=/opt/local/java/current
export JAVA_HOME
JDK_HOME=$JAVA_HOME
export JDK_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
Now if you need to switch jdks you can just swap the symlink
rm /opt/local/java/current
ln -s /opt/local/java/new_jdk_directory current
It appears that on UBUNTU this problem has been solved with update-java-alternatives which will update all of the alternatives for a given runtime or development kit (JRE/JDK).