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

10

56

I would like to know what JAVA_HOME is. 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?

Diapason answered 8/1, 2010 at 3:25 Comment(1)
A more clear what is JAVA_HOME question: #5102522Darksome
A
70

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

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.

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.

Allix answered 8/1, 2010 at 3:27 Comment(3)
@Rajper I don't think JAVA_HOME helps to locate JDK. It is only for JREDoolie
JAVA_HOME basically to the root of JRE or JDK, while path is a separate story that makes you available executable files.Sternlight
It happens that if you have JAVA_HOME, the program java will actually respect that and forward the command to whatever JRE is defined there. So it is not only 3rd parties who respect JAVA_HOME, java itself does. Check this explanation: clojureverse.org/t/…Chesterfieldian
B
19

JAVA_HOME and JRE_HOME are 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 JDK or JRE. If you are not using software that requires them, you do not need to set JAVA_HOME and JRE_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. 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. Courtesy: coderanch

Bookworm answered 31/12, 2014 at 4:32 Comment(0)
S
14

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
Spectroradiometer answered 4/7, 2013 at 12:54 Comment(0)
H
12

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

Heptamerous answered 8/1, 2010 at 3:28 Comment(0)
T
3

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.

Transmigrant answered 8/1, 2010 at 3:40 Comment(0)
L
0

JAVA HOME is 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.

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.

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!!

Lydie answered 3/3, 2019 at 8:41 Comment(0)
Z
0

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. JRE is only meant for running java applications. JDK = JRE + Development tools

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. This is automatically done for you when you install Java software. 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.

Zymo answered 26/6, 2022 at 15:49 Comment(0)
R
-1

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

Redistrict answered 23/10, 2016 at 2:0 Comment(1)
Old question. A better answer is to point to the Oracle help page on setting JAVA_HOME.Catricecatrina
M
-2

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

Mitchellmitchem answered 18/4, 2016 at 23:49 Comment(0)
C
-2

Basically JAVA_HOME is 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 , ANT and Maven. 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 .

follow the steps :

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..

Camelback answered 22/4, 2016 at 12:6 Comment(1)
JAVA_HOME should not include the 'bin' directory.Amen

© 2022 - 2024 — McMap. All rights reserved.