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)
From man update-alternatives : Each alternative has a priority associated with it. When a link group is in automatic mode, the alternatives pointed to by members of the group will be those which have the highest priority.
update-alternatives creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system. It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time.
update-java-alternatives is a program to update alternatives for jre/jdk installations. update-alternatives is a symbolic link management system for linux (I'm sure there is little news here). You can, and really should, use both update-java-alternatives and update-alternatives together.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With