In Windows, JAVA_HOME
must point to the JDK installation folder (so that JAVA_HOME/bin
contains all executables and JAVA_HOME/libs
contains all default jar
libraries).
If I download Sun's JDK bundle and installs it in Linux, it is the same procedure.
However, I need to use Kubuntu's default OpenJDK package. The problem is that all executables are placed in /usr/bin
. But the jars are placed in /usr/share/java
. Since they are not under the same JAVA_HOME
folder I'm having trouble with Grails and maybe there will be trouble with other applications that expect the standard Java structure.
If I use:
JAVA_HOME=/usr
All applications and scripts that want to use any Java executable can use the standard procedure
call $JAVA_HOME/bin/executable
. However, since the jars are in a different place, they are not always found (example: in grails I'm gettingClassDefNotFound
fornative2ascii
).On the other hand, if I use:
JAVA_HOME=/usr/share/java
None of the Java executables (
java
,javac
, etc.) can be found.
So, what is the correct way of handling the JAVA_HOME
variable in a Debian-based Linux?
Thanks for your help, Luis
Try setting the JAVA_LIB variable also.
I've discovered similar problems with the openjdk-6-jre and openjdk-6-jre-headless packages in Ubuntu.
My problem was solved by purging the openjdk-6-jre and openjdk-6-jre-headless packages and re-installing. The alternatives are only updated on a fresh install of the openjdk-6-jre and openjdk-6-jre-headless packages.
Below is a sample of installing after purging:
You can see above that
update-alternatives
is run to set up links for the various Java binaries.After this install, there are also links in
/usr/bin
, links in/etc/alternatives
, and files for each binary in/var/lib/dpkg/alternatives
.Let's contast this with installing without purging.
As you see,
update-alternatives
is not triggered.After this install, there are no files for the Java binaries in
/var/lib/dpkg/alternatives
, no links in/etc/alternatives
, and no links in/usr/bin
.The removal of the files in
/var/lib/dpkg/alternatives
also breaksupdate-java-alternatives
.As an update for fedora user , alternatives set current java directory to /usr/java/default
so you have to set your JAVA_HOME to /usr/java/default to always have alternatives curent selection in your classpath
HTH !
Updated answer that will solve your problem and also just a general good how-to for installing Oracle Java 7 on Ubuntu can be found here: http://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux
What finally worked for me (Grails now works smoothly) is doing almost like Steve B. has pointed out:
This way if the user changes the default JDK for the system,
JAVA_HOME
still works.default-java
is a symlink to the current JVM.If you use alternatives to manage multiple java versions, you can set the
JAVA_HOME
based on the symlinked java like this: