Added by Mathijs Brand, last edited by Mathijs Brand on Sep 04, 2007
()
Windows
With two batch files it is very easy to switch between two different JDK versions, e.g. 1.4.2 and 1.5.0:
jdk14.bat
@echo off echo Setting JAVA_HOME set JAVA_HOME=C:\j2sdk1.4.2_12 echo setting PATH set PATH=C:\j2sdk1.4.2_12\bin;%PATH% echo Display java version java -version
jdk5.bat
@echo off echo Setting JAVA_HOME set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_12 echo setting PATH set PATH=C:\Program Files\Java\jdk1.5.0_12\bin;%PATH% echo Display java version java -version
Automatically choose JDK when opening command line
For convenienve, you can create different shortcuts for opening command lines with different JDKs.
- Right click on your shortcut for opening a command line
- Choose tab "Shortcut"
- In field "Target", add the option /k name-of-batch-file at the end, e.g.
%windir%\system32\cmd.exe /k jdk14
Make sure the batch file is either in the directory you open the command line in, or in the PATH.
- Click "OK"! Done!
Listen very carefully, I shall say this only once 1
|
JAVA_HOME and the path to java must always refer to the exact same version of the JDK. If you mix them up, unpredictable things will happen! |
|
Be careful with switching between different JDK versions. Always check which version you are using before deploying artifacts to a Maven repository. |
|
When installing Java, binaries will also be placed in C:\WINDOWS\SYSTEM32. These might overrule the ones in your JAVA_HOME\bin directory, depending on your path. |