0

I have many Java versions installed on a Windows 7 machine. Some of them are 32 bits, some are 64 bits. Now as default it starts one of those last versions (1.7 64 bits). How do I tell my Windows 7 machine to use another version of Java? One of the reasons is that I'm developing a JNI project from Microsoft Visual Studio C++ - it uses also java 1.7 64 bits.

Best regards, Andrej

I have set:

User variable: JAVA_HOME=C:\j2sdk1.4.2_04 PATH=%JAVA_HOME%\bin;%PATH%

and system variable: JAVA_HOME=C:\j2sdk1.4.2_04 PATH=...a_lot_of_paths...;%JAVA_HOME%\bin;%PATH%

I had no idea which is better to set - for user or system settings. Done both.

System restart.

And...it didn't helped :( When I run "java -version" from cmd i have java 1.7, but not java 1.4 like defined in PATH.

after run C:>where java I got two results:

C:\Windows\System32\java.exe C:\j2sdk1.4.2_04\bin\java.exe

Who let Java go to my windows directory ???!!!

How to deal with that?

vico
  • 17,051
  • 45
  • 159
  • 315

6 Answers6

0

Try setting the JAVA_HOME environment variable. It might help but I'm not sure if Microsoft Visual studio respects it.

JAVA_HOME should be set to the directory where the JRE/JDK you want to use is located.

  • but there is now such environment variable in my machine at the moment. Where is very basic setup that tells to windows what to run? – vico Jul 04 '12 at 13:28
  • Apart from the JAVA_HOME, you will also need to change the PATH variable to PATH=%JAVA_HOME%\bin;%PATH%. Might be better off with a restart as well. – carlspring Jul 04 '12 at 13:31
0

You can find path to java tools (javac, java, javaw etc.) in your PATHvariable. So you can edit your PATH variable to use different java versions. If you use something additional (like application servers) you should check documentation and set appropriate system variables (JAVA_HOME etc.)

gkuzmin
  • 2,414
  • 17
  • 24
0

maybe try:

set JAVA_HOME=C:\jdk1.6.0u24
set PATH=%JAVA_HOME%\bin;%PATH%

and see those topics:

JRE installation directory in Windows

unix "which java" equivalent command on windows?

Community
  • 1
  • 1
Doszi89
  • 357
  • 2
  • 5
  • 20
0

Set JAVA_HOME:

JAVA_HOME="c:\path\to\jdk"

Set PATH:

PATH=%JAVA_HOME%\bin;%PATH%

Also, you might want to have a look at the Control Panel where there is a Java Settings/Java Control Panel and you can also set the default from there, but this will only be valid for use from your browsers, if I recall correctly.

You will also most-likely need to restart.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • I have set: User variable: JAVA_HOME=C:\j2sdk1.4.2_04 PATH=%JAVA_HOME%\bin;%PATH% and system variable: JAVA_HOME=C:\j2sdk1.4.2_04 PATH=...a_lot_of_paths...;%JAVA_HOME%\bin;%PATH% I had no idea which is better to set - for user or system settings. Done both. System restart. And...it didn't helped :( When I run "java -version" from cmd i have java 1.7, but not java 1.4 like defined in PATH. after run C:\>where java I got two results: C:\Windows\System32\java.exe C:\j2sdk1.4.2_04\bin\java.exe Who let Java go to my windows directory ???!!! How to deal with that? – vico Jul 04 '12 at 15:10
  • %JAVA_HOME%\bin; needs to be in the very beginning of your PATH variable, otherwise any previous installation on the PATH will be picked up first. – carlspring Jul 04 '12 at 15:22
0

The answer from @carlspring is correct if you want to set your default Java configuration that will affect all applications that are running on your Windows 7 box, but I don't belive this is what you are asking for.

If you require Visual Studio to use a different JDK from the one used by default, then you will have to configure this separately for Visual Studio.

Set this by editing VCVARS32.BAT (usually found in C:\Program Files\Microsoft Visual Studio\VC98\Bin) and adding a line like this...

set PATH=C:\\Java\\jdk1.6.0_03\\bin;%PATH%

...then you're telling VS to use this older JDK than it would by default.

Further reading : MSDN Setting the Path and Environment Variables for Command-Line Builds

Brad
  • 15,186
  • 11
  • 60
  • 74
  • I use MSVS10. And I found file vcvars32.bat in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin directory. I put lines – vico Jul 04 '12 at 19:20
0

Go to your control Panel, and open classic view, Click Java to bring up the Java Control Panel, Click the Java Tab and Click the view button. it will show you every java Runtime environment that is visible on your Computer, you can then enable and disable the other ones leaving only the one that you want.

greenkode
  • 4,001
  • 1
  • 26
  • 29