What is the correct target for the JAVA_HOME environment variable for a Linux OpenJDK Debian-based distribution?

Luis Soeiro picture Luis Soeiro · Mar 19, 2009 · Viewed 137.7k times · Source

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.

  1. 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 getting ClassDefNotFound for native2ascii).

  2. 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

Answer

Luis Soeiro picture Luis Soeiro · Mar 19, 2009

What finally worked for me (Grails now works smoothly) is doing almost like Steve B. has pointed out:

JAVA_HOME=/usr/lib/jvm/default-java

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.