JAVA_HOME and java -version
Asked Answered
C

8

19

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?

Calvillo answered 21/5, 2012 at 14:22 Comment(3)
It doesn't give any error btwCalvillo
Show output of echo %PATH%.Retardation
That isn't enough. Prepend JAVA_HOME\bin to PATH.Abisia
W
11

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

Wychelm answered 21/5, 2012 at 14:27 Comment(0)
D
18

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.

Dope answered 10/2, 2017 at 10:41 Comment(0)
W
11

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

Wychelm answered 21/5, 2012 at 14:27 Comment(0)
A
6

Make sure that the PATH environment variable is pointing to %JAVA_HOME%\bin.

Allain answered 21/5, 2012 at 14:25 Comment(0)
D
2

Be sure not to mix the system variable path and the user variable system path. I feel OK in calling java without the absolute path (when I know how JAVA_HOME and PATH are configured).

Decimal answered 24/10, 2012 at 21:20 Comment(0)
O
0

Calling java -version from command line, causes cmd.exe to do the lookup on the "known" directories. "Known" means PATH environment variable. It seems that your PATH contains a java 1.3 bin folder, and not 1.6.

JAVA_HOME is another variable, that is used (for example, and not only) by java wrappers, or by scripts executing some java stuff.

Try doing this:

SET JAVA_HOME=C:/Program Files/Java/jdk1.6.0_32
%JAVA_HOME%/bin/java -version

Add quotes where needed.

Ossa answered 21/5, 2012 at 14:26 Comment(0)
H
0

I had similar issue,in my case , I had two versions java installed. it can be fixed by uninstalling one version of java completely from system.

Hinayana answered 6/5, 2017 at 15:40 Comment(0)
L
0

Had a similar scenario today - two Windows 10 devices - both have JRE 1.6 & 1.7.

When typing

 Java -version 

One device shows 1.6 the other 1.7.

This was preventing me running a third party JAR to install some software on the device showing 1.6 (which worked fine on the device showing 1.7 when running java -version), using:

  java -jar ThirdParty.jar 

As the JAR needed to be run by 1.7.

Cause of this was in the PATH environment variable - one device had the location of 1.6 first in the PATH list, moving the 1.7 location above the 1.6 location resulted in consistency using Java -version and allowed me to install the software.

Latea answered 11/12, 2019 at 10:26 Comment(0)
S
0

java -version will consult the paths in the special environment variable Path. You need to select the java version you want and move it upwards the latter (click "Move Up"). You probably have that reference to JDK 1.3 in Path above your addition of JDK 1.6. Since that's the first thing the OS finds, that's what it chooses to run.

Executing the command again with the same window opened after changing the environment variables will not work. Re-open it

I know this question is old but this was my case and I wanted to re-explain further, similar to @DanBot 's case

Summerville answered 23/6, 2022 at 23:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.