What is the correct target for the JAVA_HOME envri

2019-01-16 08:44发布

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

13条回答
你好瞎i
2楼-- · 2019-01-16 09:21

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 environment 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
查看更多
唯我独甜
3楼-- · 2019-01-16 09:21

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

查看更多
女痞
4楼-- · 2019-01-16 09:25

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!

查看更多
Juvenile、少年°
5楼-- · 2019-01-16 09:27

Ubuntu 12.04 this works...

JAVA_HOME=/usr/lib/jvm/java-6-openjdk-i386/jre

查看更多
可以哭但决不认输i
6楼-- · 2019-01-16 09:29

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.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-16 09:33

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.

查看更多
登录 后发表回答