20

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?

10 Answers 10

20

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.

| improve this answer | |
19

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?

| improve this answer | |
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.

| improve this answer | |
  • 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
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.

| improve this answer | |
1

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.

| improve this answer | |
1

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

| improve this answer | |
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.

| improve this answer | |
-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
| improve this answer | |
-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.

| improve this answer | |
-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.

| improve this answer | |
  • 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.