Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

6 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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.

share|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
add comment

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.

share|improve this answer
    
+1 for the Maven part! –  Silviu Burcea Jun 14 at 6:28
add comment

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?

share|improve this answer
add comment

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
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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