Java Glossary : flipping JVMs

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : F words : flipping JVMs.

flipping JVMs
If you value your sanity, never install more than one JVM on a machine at a time. However, you may be forced into doing it. How do you flip back and forth between the different versions of the JDK/JREs?

Changing Command Line java.exe, javaw.exe javaws.exe and javac.exe

There are five ways to control which java.exe, javaw.exe, javaws.exe and javac.exe you get.
  1. Put J:\j2sdk1.4.2_04\bin as the very first thing on the path even before C:\winnt\system32. To change the path, click control panel | system | advanced | environment | path | edit. Your changes won't take effect until you start a new DOS box. This will also switch which javac.exe you get.
  2. Use explicit directory names in all your references to java.exe e.g. J:\j2sdk1.4.2_04\bin\java.exe and J:\j2sdk1.4.2_04\bin\javac.exe
  3. Use the JAVA_HOME environment variable, or a temporary override:

    SET JAVAHOME=J:\j2sdk1.4.2_04
    

    Refer to %JAVA_HOME%\bin\java.exe and %JAVA_HOME%\bin\javac.exe in all your *.bat files.

  4. Capture and restore the state of the registry and the C:\WINNT\system32 files. The idea is you capture the state of a JVM just after it is installed. You can the get back there, no matter what strange stuff has happened to the files or the registry. Once you have captured various configurations, you can restore whichever one you want. This is good protection even if you don't plan to switch JVMs on the fly.

    The key is, to run a version of the JVM, the registry must be set up to point to it, and its java.exe, javaw.exe and javaws.exe must be in the C:\winnt\system32 directory as the first version encountered on the path. They can then use the registry to find the other related files.

    @echo off
    echo capture.bat saving Java System state in C:\env\%1
    C:
    md! \env\%1
    cd \env\%1
    
    REM export Java region of registry
    regedit /E java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
    
    REM collect this version's java*.exe files
    
    copy C:\winnt\system32\java.exe
    copy C:\winnt\system32\javaw.exe
    copy C:\winnt\system32\javaws.exe
    
    REM collect the deployment.properties file for Java WebStart
    copy C:\Documents and Settings\Administrator\Application Data\Java\Deployment\deployment.properties
    
    dir
    
    REM -30-
    

    @echo off
    echo restore.bat restoring Java System state from C:\env\%1
    C:
    cd \env\%1
    
    REM import Java region of registry
    regedit java.reg
    
    REM restore this version's java*.exe files
    
    copy java.exe C:\winnt\system32
    copy javaw.exe C:\winnt\system32
    copy javaws.exe C:\winnt\system32
    
    Rem restore deployment.properties file for Java WebStart
    copy deployment.properties C:\Documents and Settings\Administrator\Application Data\Java\Deployment
    
    REM -30-
    

  5. Write a program to fiddle the registry entries and copy the appropriate java.exe, javaw.exe and javaws.exe to C:\winnt\system32 where they will be the first copies visible on the path.

Verifying

Verify you are getting the effect you want by typing:

java.exe -version

Unfortunately javac.exe does not have a -version option, but you can get to recognize the different versions by what they display when you type javac -X. javaw.exe and javaws.exe don't have a -version option either, but once you get java.exe working the others are usually correct to.

Controlling the JRE for your Browser

In theory, you should be able to use click Control Panel | Java and select which JVM of the ones installed you want to use in your browsers. Unfortunately, I have found once you install 1.5 beta, suddenly the other JVMs become invisible. You can also turn Java support on and off for each browser. If the browser can't see Java, click Control Panel | Java, Click browser support off, click apply, click browser support on again, then click apply.

Controlling the JRE for Java Web Start

You control which version of javaws.exe as for java.exe, however, the Java Web Start app itself uses the JNLP file to request which version of the JVM it prefers. It automatically selects the best of what you have available where the JNLP file defines best.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 690.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/flipping.html J:\mindprod\jgloss\flipping.html