views:

3113

answers:

7

Folks

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

A: 

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!

leeand00
When using debian you really need to keep with the debian structures or later system updates will leave you with a broken system.
Richard Riley
A: 

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.

iny
I usually don't have it either. However, if I don't set it up, grails complains that JAVA_HOME is not there and aborts.
Luis Soeiro
ant needs it too in debian which is the context
Richard Riley
+1  A: 

The standard Ubuntu install seems to put the various java versions in /usr/lib/jvm. The javac , 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 env. variable and make sure to have the new java bin 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.:

/usr/bin/java --> /opt/jdk/bin/java,

/opt/jdk --> /opt/jdk1.6.011

Steve B.
it is dangerous to recommend Ubuntu solutions with Debian. They can and do vary.
Richard Riley
+2  A: 

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.

Thanks Steve

Luis Soeiro
A: 

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 use update-java-alternatives. More info at:

https://help.ubuntu.com/community/Java

elcuco
update-alternatives is not enough. It needs to be update-java-alternatives
Richard Riley
@Richard: yes, noted. First time I head about it so I googled, and found Ubuntu's documentation. Thanks!
elcuco
A: 

Try setting the JAVA_LIB variable also.

Lieven
A: 

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.

Tobias Schulte