I have been trying to figure out the best way to run OpenJDK Java Runtime as default Java for my Fedora box and use Oracle JDK 6 for Android development namely for running Android SDK Manager, Android Studio and Eclipse from Android Bundle.
I installed OpenJDK Java Runtime from the Fedora repository which has setup alternatives as follow.
[donnie@fedora ~]$ alternatives --list | grep java
jre_openjdk auto /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64/jre
jre_1.7.0 auto /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64/jre
java auto /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.5.1.fc20.x86_64/jre/bin/java
libjavaplugin.so.x86_64 auto /usr/lib64/IcedTeaPlugin.so
I have installed the Oracle JDK 6 using the rpm provided by Oracle.
I could make Android Bundle and Studio make use of JAVA_HOME to run under Oracle JDK by sticking following in .bashrc
.
export JAVA_HOME=/usr/java/jdk1.6.0_45/
export PATH=$JAVA_HOME/bin:$PATH
I noticed that Chrome still uses OpenJDK (as I still need to link the plugin).
What are the difference between JAVA_HOME and using alternatives?
Best Answer
Alternatives
Alternatives is a tool that will manage the locations of the installed software using links under the control of the
alternatives
tool.These links are ultimately managed under
/etc/alternatives
with intermediate links created under a directory in$PATH
, typically/usr/bin
.Example
$JAVA_HOME
$JAVA_HOME
is where software can be told to look through the use of an environment variable. Adding it to the$PATH
simply adds the executables present in$JAVA_HOME/bin
to your$PATH
. This is sometimes necessary for certain applications.The 2 mechanisms are related but can be used together or independent of each other, it really depends on the Java application which mechanism is preferable.
What I do
I typically use
$JAVA_HOME
for some GUI applications, but in general use it only for server installations that make use of Jetty, Tomcat, or JBOSS, for example.For these installations I'll still use
alternatives
to manage the Java installations prior to setting the$JAVA_HOME
. I like doing it this way in cases where I might need to have multiple installations of Java.Alternatives does allow you to have certain tools use one installation of Java while other tools use a completely different one.
References