简体   繁体   English

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

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

I would like to know what is JAVA_HOME.我想知道什么是JAVA_HOME。 Where do I set the path of javac.exe and java.exe. javac.exe和java.exe的路径在哪里设置。 It is in environment variables.它在环境变量中。 When I compile a Java program from command prompt, how does the JVM find javac.exe ?当我从命令提示符编译 Java 程序时,JVM 如何找到javac.exe

JVM does not find java.exe . JVM 找不到java.exe It doesn't even call it.它甚至不叫它。 java.exe is called by the operating system (Windows in this case). java.exe由操作系统(在本例中为 Windows)调用。

JAVA_HOME is just a convention, usually used by Tomcat, other Java EE app servers and build tools such as Gradle to find where Java lives. JAVA_HOME只是一个约定,通常由 Tomcat、其他 Java EE 应用服务器和构建工具(如Gradle )使用来查找 Java 所在的位置。

The important thing from your point of view is that the Java /bin directory be on your PATH so Windows can find the .exe tools that ship with the JDK: javac.exe , java.exe , jar.exe , etc.从您的角度来看,重要的是 Java /bin目录位于您的PATH上,因此 Windows 可以找到 JDK 附带的.exe工具: javac.exejava.exejar.exe等。

JAVA_HOME and JRE_HOME are not used by Java itself. Java 本身不使用JAVA_HOMEJRE_HOME Some third-party programs (for example Apache Tomcat) expect one of these environment variables to be set to the installation directory of the JDK or JRE .一些第三方程序(例如 Apache Tomcat)期望将这些环境变量之一设置为JDKJRE的安装目录。 If you are not using software that requires them, you do not need to set JAVA_HOME and JRE_HOME .如果您没有使用需要它们的软件,则不需要设置JAVA_HOMEJRE_HOME PATH is an environment variable used by the operating system (Windows, Mac OS X, Linux) where it will look for native executable programs to run. PATH是操作系统(Windows、Mac OS X、Linux)使用的环境变量,它将在其中查找要运行的本机可执行程序。 You should add the bin subdirectory of your JDK installation directory to the PATH , so that you can use the javac and java commands and other JDK tools in a command prompt window.您应该将JDK安装目录的bin子目录添加到PATH中,以便您可以在命令提示符窗口中使用javacjava命令以及其他JDK工具。 Courtesy : coderanch礼貌coderanch

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

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

JAVA_HOME is a environment variable (in Unix terminologies), or a PATH variable (in Windows terminology). JAVA_HOME 是环境变量(在 Unix 术语中)或 PATH 变量(在 Windows 术语中)。 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 应用程序(需要 JDK/JRE)运行,会在 JAVA_HOME 变量中查找 Java 编译器/解释器所在的位置。

JAVA HOME is used for setting up the environment variable for JAVA. JAVA HOME用于设置 JAVA 的环境变量。 It means that you are providing a path for compiling a JAVA program and also running the same.这意味着您正在为编译和运行 JAVA 程序提供路径。 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( PATH ) 并尝试在命令提示符下运行 java 或任何依赖程序。

You will deal with an error as javac : not recognized as internal or external command .您将处理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.现在要设置它,只需打开您的 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!!就这样!!

JAVA_HOME is an environment variable which is read by some development tools like Apache Tomcat, Apache Maven, Gradle, Jenkins etc. Usually, JAVA_HOME is set to point to JDK instead of JRE because these development tools need to use tools like compiler, debugger, document generator etc. which are only available in JDK since JDK is a development kit. JAVA_HOME是一个环境变量,由一些开发工具如 Apache Tomcat、Apache Maven、Gradle、Jenkins 等读取。通常, JAVA_HOME设置为指向 JDK 而不是 JRE,因为这些开发工具需要使用编译器、调试器、文档等工具生成器等仅在 JDK 中可用,因为 JDK 是一个开发工具包。 JRE is only meant for running java applications. JRE 仅用于运行 java 应用程序。 JDK = JRE + Development tools JDK = JRE + 开发工具

Consumer facing Java applications don't read JAVA_HOME variable and they just need to know where the JVM is located and that's why JVM location (directory) needs to be added to the PATH variable.面向消费者的 Java 应用程序不会读取JAVA_HOME变量,他们只需要知道 JVM 所在的位置,这就是需要将 JVM 位置(目录)添加到PATH变量中的原因。 This is automatically done for you when you install Java software.这在您安装 Java 软件时会自动为您完成。 Whenever you try to run a Java application by either double clicking on the app or through command line, your operating system reads PATH variable to locate and run JVM and it doesn't look for JAVA_HOME variable.每当您尝试通过双击应用程序或通过命令行来运行 Java 应用程序时,您的操作系统都会读取PATH变量来定位和运行 JVM,并且它不会查找JAVA_HOME变量。

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

JAVA_HOME is an Environment Variable set to the location of the Java directory on your computer. JAVA_HOME 是一个环境变量,设置为您计算机上 Java 目录的位置。 PATH is an internal DOS command that finds the /bin directory of the version of Java that you are using. PATH 是一个内部 DOS 命令,用于查找您正在使用的 Java 版本的 /bin 目录。 Usually they are the same, except that the PATH entry ends with /bin通常它们是相同的,除了 PATH 条目以 /bin 结尾

Basically JAVA_HOME is use to set path of the java .基本上JAVA_HOME用于设置 java 的路径。 it is use in windows.它在 Windows 中使用。 it's used for set path of the multiple software like as java EE , ANT and Maven .用于java EEANTMaven等多个软件的路径设置。 this is the steps to solve your problem:这是解决您的问题的步骤:

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_HOME in 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 ;路径: JAVA_HOMEANT_HOME it is the systematic way to set the environment variable..这是设置环境变量的系统方法..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM