基于 Linux OpenJDK Debian 的发行版的 JAVA_HOME 环境变量的正确目标是什么? [英] What is the correct target for the JAVA_HOME environment variable for a Linux OpenJDK Debian-based distribution?
问题描述
在 Windows 中,JAVA_HOME
必须指向 JDK 安装文件夹(这样 JAVA_HOME/bin
包含所有可执行文件,JAVA_HOME/libs
包含所有默认 jar
库).
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).
如果我下载 Sun 的 JDK 包并将其安装在 Linux 中,则是相同的过程.
If I download Sun's JDK bundle and installs it in Linux, it is the same procedure.
但是,我需要使用 Kubuntu 的默认 OpenJDK 包.问题是所有可执行文件都放在 /usr/bin
中.但是罐子放在 /usr/share/java
中.由于它们不在同一个 JAVA_HOME
文件夹下,因此我在使用 Grails 时遇到了问题,而且其他需要标准 Java 结构的应用程序可能也会遇到问题.
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
想要使用任何 Java 可执行文件的所有应用程序和脚本都可以使用标准过程 call $JAVA_HOME/bin/executable
.但是,由于 jar 位于不同的位置,因此并不总是能找到它们(例如:在 grails 中,我为 native2ascii
获取了 ClassDefNotFound
).
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
).
另一方面,如果我使用:
On the other hand, if I use:
JAVA_HOME=/usr/share/java
找不到任何 Java 可执行文件(java
、javac
等).
None of the Java executables (java
, javac
, etc.) can be found.
那么,在基于 Debian 的 Linux 中处理 JAVA_HOME
变量的正确方法是什么?
So, what is the correct way of handling the JAVA_HOME
variable in a Debian-based Linux?
感谢您的帮助,路易斯
推荐答案
最终对我有用的(Grails 现在工作顺利)几乎就像 Steve B. 指出的那样:
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
这样如果用户更改了系统的默认 JDK,JAVA_HOME
仍然有效.
This way if the user changes the default JDK for the system, JAVA_HOME
still works.
default-java
是当前 JVM 的符号链接.
default-java
is a symlink to the current JVM.
这篇关于基于 Linux OpenJDK Debian 的发行版的 JAVA_HOME 环境变量的正确目标是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!