I have installed JDK 5, JDK 6 and JDK 7 on my Windows PC. I have added the binary folders of all three versions in the PATH variable. I can use different versions for different projects with IDEs. But, how do I use a specific version of javac in cmd or PowerShell?
3 Answers
cmd will pick the first JDK in your path. You only want one there.
To use different ones you can use path variables like JAVA_HOME and change it when you need to. Or do it like Bhavik Ambani specified. You will have to restart the cmd after you change your path for it to pick it up.

- 14,672
- 5
- 54
- 79
For that you should write the explicit path of the javac location.
E.g. (for PowerShell)
& "H:\Program Files\Java\jdk1.7.0\bin\javac.exe" JavaFile
E.g. (for cmd)
"H:\Program Files\Java\jdk1.7.0\bin\javac.exe" JavaFile

- 2,533
- 1
- 17
- 13

- 6,557
- 14
- 55
- 86
cmd
will pick the first binary it finds in PATH
, so depending on the order of your Java directories javac
from JDK 5, 6 or 7 will be called when you type javac
.
You can create links to different versions of javac
and name them e.g. javac5
, javac6
and javac7
and use these from the command line instead.
If you're calling javac
from a build system, a makefile or a script you can use full paths instead.

- 26,643
- 4
- 71
- 92
-
How to create links to different versions? – Mike Peterson May 07 '12 at 20:01
-
For windows something like C:\>MKlink ss64 C:\Windows\system32\notepad.exe read http://ss64.com/nt/mklink.html or http://stackoverflow.com/a/9362812/643500 – Sully May 07 '12 at 20:15