31

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?

14 Answers 14

30

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.

2
  • 3
    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, 2020 at 5:06
  • C:\Program Files\Common Files\Oracle\Java\javapath
    – iamgr007
    Nov 14, 2022 at 6:10
30

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
9

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, 2011 at 19:29
  • It's an example, the procedure is still the same..
    – user1931
    Jan 25, 2011 at 19:31
7

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.

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.

2
  • 2
    This has been suggested already, 2 years ago
    – Ramhound
    Jan 28, 2018 at 3:43
  • Thank you that worked for me
    – dbnex14
    Jul 8, 2021 at 18:43
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
  • 1
    I did the same and have now all good on my system. I am not sure why someone downwoted your comment but it worked for me. I do however see Oracle\Java\javapath being added to my System Environent Path variable every once in a while and that then screws up my Eclipse. So, each time it happens, I go to Env and remove Oracle/Java/javapath and then everything is good again.
    – dbnex14
    Jul 8, 2021 at 18:41
1

Developer use developer way. You can hanker into idea.bat file and add below line to point any JRE before it start as below:

...
IF "%JRE%" == "" (
  IF EXIST "%JDK_HOME%" (
    SET "JRE=%JDK_HOME%"
  ) ELSE IF EXIST "%JAVA_HOME%" (
    SET "JRE=%JAVA_HOME%"
  )
)

**SET JRE=<YOU WANT>**

SET "JAVA_EXE=%JRE%\bin\java.exe"
IF NOT EXIST "%JAVA_EXE%" (
  ECHO ERROR: cannot start IntelliJ IDEA.
  ECHO No JRE found. Please make sure IDEA_JDK, JDK_HOME, or JAVA_HOME point to a valid JRE installation.
  EXIT /B
)
...

But you need to setup very high version JDK for it as actually IDEA want us use self contain java but the version is very higher than the one which developer usually used. So it will contain one JDK version which is suitable for IDEA and add one ENV property like %IDEA_JDK% and point it when you install IDEA.

BUT if you didn't follow up all process when install or update IDEA( like didn't have permission and it also will be installed but it will install under your AppData folder and some env property will not be setup properly like $IDEA_JDK%). In that case it will use local JDK based on your %JAVA_HOME%. And as we said, IDEA will use very high version than developer use, you will got below error like:

CompileCommand: exclude com/intellij/openapi/vfs/impl/FilePartNodeRoot.trieDescend
Error occurred during initialization of VM

    java.lang.UnsupportedClassVersionError: com/intellij/util/lang/PathClassLoader has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

So you can set JRE to the self-contain JDK folder (usually under %IDEA_HOME%/jbr), it will works absolutely.

1

I have to use both jdk 7 and jdk 8 on my windows 10 pc. Although %JAVA_HOME% is defined as jdk8, java -version command shows jdk 1.7 and I cannot run jdk8 required applications like Eclipse Oxygen. C:\Program Files (x86)\Common Files\Oracle\Java\javapath is removed from path variable on system environment and also java.exe, javaw.exe and javaws.exe files are deleted in System32. Java version value in System registry is 1.8. Solution is very simple. Just delete the JAVA_HOME value in system environment and then define it again.

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

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.

2
  • 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, 2021 at 7:45
  • I am voting your answer up since that is exactly what I see on my system and it fixes my issues. Thank you @Sudheep
    – dbnex14
    Jul 8, 2021 at 18:43
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .