Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 510
Luis Soeiro Avatar asked Mar 19 '09 19:03

Luis Soeiro


People also ask

What should JAVA_HOME point to Linux?

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.

What is JAVA_HOME environment variable Linux?

2) JAVA_HOME variable is short and concise instead of full path to JDK installation directory. 3) JAVA_HOME variable is platform independence i.e. if your startup script uses JAVA_HOME then it can run on Windows and UNIX without any modification, you just need to set JAVA_HOME on respective operating system.

What is the correct JAVA_HOME path?

Set JAVA_HOME: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.

What is the JAVA_HOME environment variable?

JAVA_HOME is an operating system (OS) environment variable which can optionally be set after either the Java Development Kit (JDK) or the Java Runtime Environment (JRE) is installed. The JAVA_HOME environment variable points to the file system location where the JDK or JRE was installed.


1 Answers

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.

like image 131
Luis Soeiro Avatar answered Oct 12 '22 11:10

Luis Soeiro