25

My JAVA_HOME is set to C:\bea\jdk150_10\bin (Java 1.5). However, when I run java -version I get the following:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

How can I use the 1.5 version?

12 Answers 12

23

As Mikel has mentioned, In your machine java is taken from C:\Windows\System32\java.exe.

Change the Path in the System Environment variables as mentioned by John T.

And modify it have the C:\bea\jdk150_10\bin before %SystemRoot%\system32 in the path.

1
  • 2
    People normally forget to check the order, they just check if the entry in there in env variables. Thanks for mentioning this. – Dexter Sep 29 '20 at 5:06
22

Run

where java

at your command prompt.

On my system, it printed something quite unexpected:

C:\Users\Mikel>where java
C:\Windows\System32\java.exe

Verifying there really is a Java there:

C:\Users\Mikel>c:\windows\system32\java.exe -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

So one solution is to ensure your preferred Java is in the PATH before C:\Windows\System32.

I also tried looking in the Java control panel to see if it manages the version in C:\Windows\System32, but I could only view the settings, not edit them. Maybe it works for you?

1
8

Modify the PATH variable, not JAVA_HOME.

See the Java documentation on setting or changing your PATH variable.

  1. Start -> Control Panel -> System -> Advanced

  2. Click on Environment Variables, under System Variables, find PATH, and click on it.

  3. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.

  4. Close the window.

  5. Reopen Command prompt window, and run your Java code.

2
  • I don't see any references to jdk 6 on the PATH variable either. Only Java 5 X) – Jeune Jan 25 '11 at 19:29
  • It's an example, the procedure is still the same.. – John T Jan 25 '11 at 19:31
5

Go to advanced settings of environment variables and edit the path variable. whichever version of java you want just move up that versions path above all other environment variables of other java versions.

here in the image java_home environment variable is moved up than oracle java environment

4

Not all applications use JAVA_HOME to get the JDK version. As said before, some of them use the %SystemRoot%\System32\java.exe. You can do %SystemRoot%\java.exe -version to see which is that version.

What I have to add to the other responses is that if you build with Maven, M2_HOME\bin has also to be before %SystemRoot% in the order for Maven to use the correct JAVA_HOME version.

0
2

JAVA_HOME should not be pointing to the bin!

SET "JAVA_HOME=C:\bea\jdk150_10" SET "PATH=%JAVA_HOME%/bin;%PATH%"

Also make sure that the path to JAVA_HOME is correct! If there's a typo and C:\Windows\System32\ is in you path then that java.exe will get run instead of the one you specified.

0

For me on win 10, javac -version showed java7 and java -version showed java8.Doing "where java" on command prompt showed java at three locations. I had to remove Java from C:\Windows\System32, Remove entry of "C:\ProgramFile\Oracle\Java\javapath"and "C:\ProgramData\Oracle\Java" from path variable, keep only Jdk7 entry in path variable worked after two hour long struggle.

0

I was facing the same issue. What I did I had renamed the directory (C:\ProgramData\Oracle\Java\javapath) from javapath to javapath1 and it resolved my problem.

-1

Try this:

@echo off
DOSKEY WHICH=@for %%E in (%PATHEXT%) do @for %%I in ($*%%E) do @if NOT "%%~$PATH:I"=="" echo %%~$PATH:I
SET "JAVA_HOME=C:\Java\jdk1.6"
SET "PATH=%JAVA_HOME%\bin;%PATH%"
where.exe java
WHICH java
pause
-1

I was facing the same issue. Later I found that the culprit was Java 8.Earlier I installed java 8 but now there is no folder for java 8 and my JAVA_HOME set to jre7 but still I was facing above issue.

solution

I deleted javapath present in C:\ProgramData\Oracle\Java. Now my system working properly. It also resolved my eclipse startup problem.

-1

From Java version 8 onward the installer is adding 'C:\ProgramData\Oracle\Java\javapath' to the PATH variables. So you can remove this and use your own path variable pointing to the desired java version bin directory.

1
  • Welcome to superuser, you answered a that is ten yrs old , the versions have changed but you would have better explained with more detail why you are answering and why they should listen. It is hard with an old question when you can comment it maybe better suited to that. Once you have sufficient reputation you will be able to comment on any post. again welcome to superuser and keep coming back. – mic84 Feb 25 at 7:45
-2

I had the same issue. Doing this I resolved the issue.

On Windows 8 or 10, you need to remove "C:\ProgramFile\Oracle\Java\javapath" from path in environment variable.

This may resolve the issue.

1
  • 2
    This has been suggested already, 2 years ago – Ramhound Jan 28 '18 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.