I'm using a Windows .bat script and I set JAVA_HOME
as C:/Program Files/Java/jdk1.6.0_32
when I do a java -version
, it still shows the 1.3
How can I fix this? What am I doing wrong?
The JAVA_HOME environment variable is not actually used by the locally installed Java runtime. Instead, other programs installed on a desktop computer that require a Java runtime will query the OS for the JAVA_HOME variable to find out where the runtime is installed.
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.
PATH values: notice how the directory we set for JAVA_HOME is the JDK installation root whereas for PATH we add the bin directory within the JDK installation. Take care to set these up correctly otherwise you'll have problems later on.
To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.
For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath;
was added by java windows install before my %JAVA_HOME%\bin;
.
So I'd echo %JAVA_HOME%
pointing to a JDK7 and java -version
showing jdk8.
I'd to put %JAVA_HOME%\bin;
before C:\ProgramData\Oracle\Java\javapath;
so that java -version
displays jdk7.
Try %JAVA_HOME%\bin\java -version
If you modify JAVA_HOME
, it's usually better to invoke java
with an absolute path (using JAVA_HOME
) because the new binary is probably not in the path (and then Windows will load the wrong binary).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With