Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top