One java.exe for all java versions

来源:百度文库 编辑:神马文学网 时间:2024/04/29 07:26:01
I accidentally found one useful feature of Java that I didn‘t know about.I have many Java versions installed because some programs I have only runwith some or because I need to test a program with a specific version.Until now to run a program with a specific Java version I used the fullpath to the java.exe or javaw.exe of the specific version. But I justlearned that with the "-version" command line parameter not only shows theversion but also let‘s us specify one to use with the form "-version:x"where x is a Java version. Probably it‘s just searchs for public installedJVMs and wouldn‘t find privately installed ones.
Curiously it understand"-version:1.5" to use the higher 1.5 version I have installed, but itdoesn‘t found  the 1.4.2_12 when I used "-version:1.4".
Examples: I have installed java 1.4.2_12, 1.5.0_08, 1.5.0_10 and 1.6.0.
c:\>java -version java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixedmode, sharing)
c:\>java -version:1.5 -version
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition(build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixedmode, sharing)
c:\>java -version:1.5.0_08 -version
java version "1.5.0_08"
Java(TM) 2 RuntimeEnvironment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixedmode, sharing)
c:\>java -version:1.5.0_09 -version
Unable to locateJRE meeting specification "1.5.0_09"
c:\>java -version:1.4 -version
Unableto locate JRE meeting specification "1.4"
c:\>java -version:1.4.2-version
Unable to locate JRE meeting specification "1.4.2"
c:\>java-version:1.4.2_09 -version
Unable to locate JRE meeting specification"1.4.2_09"
c:\>java -version:1.4.2_12 -version
java version"1.4.2_12"
Java(TM) 2 Runtime Environment, Standard Edition (build1.4.2_12-b03)
Java HotSpot(TM) Client VM (build 1.4.2_12-b03, mixed mode)