1

I am using Windows 10. My JAVA_HOME path is set to the location of Java 1.7 but on executing

java -version 

in cmd, it gives version as Java 1.8. Can anyone tell me why I am getting this issue and how to fix it?

EDIT: In response to some of the fixes suggested, my system variable PATH too has the path to 1.7.

Mayank Aggarwal
  • 115
  • 1
  • 11

5 Answers5

2

Check your Windows PATH. You probably installed Java 8 version and as it seems to be on the path before Java 7, this is the version that gets executed when calling java from the command line.

JAVA_HOME is not used by Windows to pick up a Java Installation but is mainly used by tools/applications that require Java (such as IDEs or applications written in Java) to find the Java to use.

See https://stackoverflow.com/a/5102501/4323935 as well.

dpr
  • 8,675
  • 3
  • 32
  • 57
1

In the System Variable PATH, the Java 7's path must be in the front, not at the end. Are you able to execute java -version from the Java 7's directory and seeing the version displayed to be correct?

sgarg
  • 159
  • 4
1

You can resolve this problem in either one of the below way

  1. In the environment variables check your path whether it is starts with or path has C:\ProgramData\Oracle\Java\javapath, if yes then please remove it
  2. Open Run then type system32 and press enter. search and find java.exe, javaw.exe and javaws.exe and delete it.

After that set the JAVA_HOME and path(ignore if you already set it up).

Once you have done the above things then close cmd and reopen and try again

this is similar to Multiple java versions installed and java was started but returned exit code=13

Sasikumar Murugesan
  • 4,056
  • 9
  • 47
  • 70
  • Yeah. These two paths were there. I'll remove them now. I wish I could accept this answer too – Mayank Aggarwal Oct 16 '18 at 05:09
  • "Delete the executables from some path" is not really good advice and not at all the right thing to do. If this is really required to fix the problem then suggestion should be to un-install the software. – sgarg Oct 17 '18 at 05:22
  • Java adds above executable when installing. This will be useful for java dummies since they don't need to do any changes but developer needs to work with multiple versions so in this case developer get confusing with multiple versions. And these executable works as default one even we add JAVA_HOME to env – Sasikumar Murugesan Oct 17 '18 at 06:05
  • I believe you can see lot of questions in stackoverflow about java path issues due to this default executable. – Sasikumar Murugesan Oct 17 '18 at 06:09
0

Try the following command. It will show you the path for java being picked up in the command line.

where java

Then, make sure it is not in your path:

set PATH
chandra
  • 490
  • 4
  • 12
0

First of all please check the PATH values typing

echo %PATH%

Most probably you have java 1.7 path set in PATH, and it might be set before other java path

Ahmet Karakaya
  • 9,092
  • 20
  • 75
  • 124