Sunday, February 14, 2010

Switching between Java versions

Original post date: Fri Jun 01 12:00:00 2007
It was always possible of course to install several Java versions on the same system, but switching from one to another has always been a bit of a nuisance. In Windows I started using batch files that I wrote specifically for the purpose of setting PATH and JAVA_HOME variables while for Linux Fedora you can use the alternatives command.
But I just found out that newer Java versions actually support switching versions directly from the command line:

 java -version:1.5+ ...
  
will require that the code is run with a VM of at least version 1.5 while:

 java -version:1.6* ...
  
will use any version 1.6 VM (so it won't accept 1.5 nor 1.7, but it will accept 1.6u1). Requiring a specific version of the VM is supported but is not recommended because it would tie you to that very VM not even allowing the use of VMs that have important bug or security fixes.Specifying a VM that can not be found on the system will result in an error of course:

 > java -version:1.4* -version
 Unable to locate JRE meeting specification "1.4*"

No comments:

Post a Comment