什么是JAVA_HOME?JVM如何找到JAVA_HOME中存储的javac路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2025290/
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-08-13 02:43:55  来源:igfitidea点击:

What is JAVA_HOME? How does the JVM find the javac path stored in JAVA_HOME?

javacore

提问by giri

I would like to know what is JAVA_HOME. Where do I set the path of javac.exe and java.exe. It is in environment variables. When I compile a Java program from command prompt, how does the JVM find javac.exe?

我想知道什么是JAVA_HOME。我在哪里设置javac.exe和java.exe的路径。它在环境变量中。当我从命令提示符编译 Java 程序时,JVM 如何找到javac.exe

采纳答案by duffymo

JVM does not find java.exe. It doesn't even call it. java.exeis called by the operating system (Windows in this case).

JVM 没有找到java.exe. 它甚至不调用它。 java.exe由操作系统调用(本例中为 Windows)。

JAVA_HOMEis just a convention, usually used by Tomcat, other Java EE app servers and build tools such as Gradleto find where Java lives.

JAVA_HOME只是一个约定,通常由 Tomcat、其他 Java EE 应用服务器和构建工具使用,例如Gradle查找 Java 所在的位置。

The important thing from your point of view is that the Java /bindirectory be on your PATHso Windows can find the .exetools that ship with the JDK: javac.exe, java.exe, jar.exe, etc.

从您的角度来看,重要的是,Java的/bin目录是在你PATH这样Windows可以找到.exe的工具,船舶与JDK: ,,等。javac.exejava.exejar.exe

回答by Kaleb Brasee

The command prompt wouldn't use JAVA_HOME to find javac.exe, it would use PATH.

命令提示符不会使用 JAVA_HOME 来查找 javac.exe,它会使用 PATH。

回答by Kaleb Brasee

JAVA_HOME is a environment variable (in Unix terminologies), or a PATH variable (in Windows terminology). A lot of well behaving Java applications (which need the JDK/JRE) to run, looks up the JAVA_HOME variable for the location where the Java compiler/interpreter may be found.

JAVA_HOME 是环境变量(在 Unix 术语中)或 PATH 变量(在 Windows 术语中)。许多运行良好的 Java 应用程序(需要 JDK/JRE)会查找 JAVA_HOME 变量以查找可能找到 Java 编译器/解释器的位置。

回答by user2546847

set environment variable

设置环境变量

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24

classpath=C:\Program Files\Java\jdk1.6.0_24\lib\tools.jar

path=C:\Program Files\Java\jdk1.6.0_24\bin

回答by raikumardipak

JAVA_HOMEand JRE_HOMEare not used by Java itself. Some third-party programs (for example Apache Tomcat) expect one of these environment variables to be set to the installation directory of the JDKor JRE. If you are not using software that requires them, you do not need to set JAVA_HOMEand JRE_HOME. PATHis an environment variable used by the operating system (Windows, Mac OS X, Linux) where it will look for native executable programs to run. You should add the binsubdirectory of your JDKinstallation directory to the PATH, so that you can use the javacand javacommands and other JDKtools in a command prompt window. Courtesy: coderanch

JAVA_HOME并且JRE_HOME不被 Java 本身使用。某些第三方程序(例如 Apache Tomcat)希望将这些环境变量之一设置为JDK或的安装目录JRE。如果您不使用需要它们的软件,则无需设置JAVA_HOMEJRE_HOMEPATH是操作系统(Windows、Mac OS X、Linux)使用的环境变量,它将在其中查找要运行的本机可执行程序。您应该将安装目录的bin子目录添加JDKPATH,以便您可以在命令提示符窗口中使用javacjava命令和其他JDK工具。礼貌coderanch

回答by Jim Arona

JAVA_HOME is an Environment Variable set to the location of the Java directory on your computer. PATH is an internal DOS command that finds the /bin directory of the version of Java that you are using. Usually they are the same, except that the PATH entry ends with /bin

JAVA_HOME 是一个环境变量,设置为您计算机上 Java 目录的位置。PATH 是一个内部 DOS 命令,用于查找您正在使用的 Java 版本的 /bin 目录。通常它们是相同的,只是 PATH 条目以 /bin 结尾

回答by RISHABHA SINGH

Basically JAVA_HOMEis use to set path of the java . it is use in windows. it's used for set path of the multiple software like as java EE, ANTand Maven. this is the steps to solve your problem:

基本上JAVA_HOME用于设置 java 的路径。它在 Windows 中使用。它用于设置多个软件的路径,如 as java EEANTMaven。这是解决您的问题的步骤:

only for core java to set path : path :"C:\Program Files\Java\jre1.8.0_77\bin"but when you are use multi built like as ANT, core java then you are used JAVE_HOMEin environment .

仅适用于核心 java 设置路径:路径:"C:\Program Files\Java\jre1.8.0_77\bin"但是当您使用多构建时ANT,核心 java 然后您JAVE_HOME在环境中使用。

follow the steps :

按照步骤 :

JAVA_HOME:"C:\Program Files\Java\jre1.8.0_77\bin"ANT_HOME:"C:\ant\apache-ant-1.9.6"

JAVA_HOME: "C:\Program Files\Java\jre1.8.0_77\bin"ANT_HOME:"C:\ant\apache-ant-1.9.6"

Path: JAVA_HOME, ANT_HOME; it is the systematic way to set the environment variable..

路径:JAVA_HOME, ANT_HOME; 这是设置环境变量的系统方法..

回答by lantian0811

use this command /usr/libexec/java_home to check the JAVA_HOME

使用此命令 /usr/libexec/java_home 检查 JAVA_HOME

回答by Ashraf.Shk786

JAVA HOMEis used for setting up the environment variable for JAVA. It means that you are providing a path for compiling a JAVA program and also running the same. So, if you do not set the JAVA HOME( PATH ) and try to run a java or any dependent program in the command prompt.

JAVA HOME用于设置JAVA的环境变量。这意味着您正在提供用于编译 JAVA 程序并运行该程序的路径。因此,如果您不设置 JAVA HOME( PATH ) 并尝试在命令提示符下运行 java 或任何依赖程序。

You will deal with an error as javac : not recognized as internal or external command. Now to set this, Just open your Java jdk then open bin folder then copy the PATH of that bin folder.

您将处理错误为 javac : not recognized as internal or external command。现在要设置它,只需打开您的 Java jdk,然后打开 bin 文件夹,然后复制该 bin 文件夹的 PATH。

Now, go to My computer right click on it----> select properties-----> select Advanced system settings----->Click on Environment Variables------>select New----->give a name in the text box Variable Name and then paste the path in Value.

现在,转到我的电脑右键单击它----> 选择属性-----> 选择高级系统设置-----> 单击环境变量----> 选择新建---- -> 在文本框中变量名中给出一个名称,然后在值中粘贴路径。

That's All!!

就这样!!