JAVA_HOME : java 安装在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13888551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:20:09  来源:igfitidea点击:

JAVA_HOME : where is java installed

javatomcat

提问by WhatIf

I'm trying to set the JAVA_HOME to get tomcat 7 to work with no success.

我正在尝试设置 JAVA_HOME 以使 tomcat 7 正常工作但没有成功。

I'm using CentOS 6.3. Here is what I did so far:

我正在使用 CentOS 6.3。这是我到目前为止所做的:

which java /usr/bin/java

哪个 java /usr/bin/java

so I edited the .bash_profile, I added

所以我编辑了 .bash_profile,我添加了

export JAVA_HOME=/usr/bin/java

导出 JAVA_HOME=/usr/bin/java

didn't work. I searched online and found another user on stackoverflow who found it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java

没有用。我在网上搜索,在stackoverflow上找到另一个用户,他在/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java

I searched on my computer and found that java is located in /usr/lib/jvm/jre-1.6.0-openjdk/bin

我在我的电脑上搜索,发现java位于/usr/lib/jvm/jre-1.6.0-openjdk/bin

I then changed the JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin , tried to start tomcat but server can't be found.

然后我将 JAVA_HOME 更改为 export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin ,尝试启动 tomcat 但找不到服务器。

How do I find where java was installed? I didn't install it myself; it was installed during linux installation.

如何找到java的安装位置?不是我自己安装的;它是在 linux 安装过程中安装的。

Thanks in advance, Mike

提前致谢,迈克

回答by Diego Basch

export JAVA_HOME=/usrshould do it. The script runs $JAVA_HOME/bin/java

export JAVA_HOME=/usr应该这样做。脚本运行$JAVA_HOME/bin/java

回答by Stephen C

The strictly correct answer is this:

严格正确的答案是这样的:

export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk

The issue is that on a typical Linux system you access the javacommand (etc) via symbolic links that are created / managed by the alternativescommand. This allows you to make a system-wide choice over which of the java installations should be used by default; i.e. via commands in /usr/bin.

问题在于,在典型的 Linux 系统上,您可以java通过由alternatives命令创建/管理的符号链接访问命令(等)。这允许您在系统范围内选择默认情况下应使用哪个 java 安装;即通过/usr/bin.

The second issue this that the JAVA_HOME environment variable should point at the Java installation directory. The "bin" directory is a subdirectory of the installation directory. (Look at the contents of "/usr/lib/jvm/jre-1.6.0-openjdk" !!)

第二个问题是JAVA_HOME环境变量应该指向Java安装目录。“bin”目录是安装目录的子目录。(看“/usr/lib/jvm/jre-1.6.0-openjdk”的内容!!)

While export JAVA_HOME=/usr/binwill work for locating the commands, it won't work if the Java application needs to find other files in the installation; e.g. the "rt.jar" file.

虽然export JAVA_HOME=/usr/bin可以用于定位命令,但如果 Java 应用程序需要在安装中查找其他文件,它将不起作用;例如“rt.jar”文件。

This "fine distinction" possibly doesn't matter for Tomcat, but it is likely to matter for other Java software that uses the JAVA_HOME convention.

这种“细微差别”对于 Tomcat 可能无关紧要,但对于使用 JAVA_HOME 约定的其他 Java 软件可能很重要。



Footnote: if you are using an Oracle Java for Linux installation, the default installation directory will be a subdirectory "/usr/java". Sadly, the Oracle installer doesn't understand that Linux "alternatives" system. You either have to register the alternatives for each of the Java commands by hand (tedious!!) or add the installation's "bin" directory to your PATH.

脚注:如果您使用 Oracle Java for Linux 安装,默认安装目录将是一个子目录“/usr/java”。遗憾的是,Oracle 安装程序不了解 Linux“替代品”系统。您要么必须手动为每个 Java 命令注册替代项(乏味!!),要么将安装的“bin”目录添加到您的 PATH。