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
The standard Ubuntu install seems to put the various Java versions in
/usr/lib/jvm
. Thejavac
, java you find in your path will softlink to this.There's no issue with installing your own Java version anywhere you like, as long as you set the
JAVA_HOME
environment variable and make sure to have the new Javabin
on your path.A simple way to do this is to have the Java home exist as a softlink, so that if you want to upgrade or switch versions you only have to change the directory that this points to - e.g.:
Please see what the update-alternatives command does (it has a nice man...).
Shortly - what happens when you have java-sun-1.4 and java-opensouce-1.0 ... which one takes "java"? It debian "/usr/bin/java" is symbolic link and "/usr/bin/java-sun-1.4" is an alternative to "/usr/bin/java"
Edit: As Richard said,
update-alternatives
is not enough. You actually need to useupdate-java-alternatives
. More info at:https://help.ubuntu.com/community/Java
My correct target has always been to download it from Sun and just install it that way. Then you know exactly what directory everything goes in.
But if you'd prefer to stick with the odd way that Debian installs it, my best guess would be the parent directory just above where the java and javac binaries are located.
(since when you specify it in your path it's $JAVA_HOME/bin) (So in your case it would be ... $JAVA_HOME/share and $JAVA_HOME would be /usr ?)
Eh, that doesn't sound right...
I'm interested to hear the answer to this too!
Ubuntu 12.04 this works...
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-i386/jre
As far as I remember, I used the update-java-alternatives script instead of the update-alternatives. And it did set the JAVA_HOME for me correctly.
I usually don't have any JAVA_HOME environment variable. Java can set it up itself. Inside java java.home system property should be available.