flipping JVMs : Java Glossary

go to home page F words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 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 (all) ©1996-2009 Roedy Green, Canadian Mind Products
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 seven ways to control which java.exe, javaw.exe, javaws.exe and javac.exe you get.
  1. Put the 
    JDK bin program directory :
    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.
    java.exe :
    and 
    javac.exe :
  3. Use the JAVA_HOME environment variable, or a temporary override:
    SET JAVAHOME=J:\Program Files\java\jdk1.6.0_17
    Then 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.

  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. However, even this won’t work for JDK 1.5. When its Java.exe sees the registry set up for 1.4 it aborts.
  6. Use the JDK 1.5 Control Panel ⇒ Java to select which JRE you wish to use. For it to work, you should install your JREs and JDKs in chronological order. The catch is the fool think hardly ever works properly.
  7. The brute force technique works like this:
    1. Go into the Control Panel and uninstall all Java JREs and JDKs.
    2. Go into the registry and wipe all vestiges of HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft.
    3. Manually wipe all vestiges of the JREs and JDKs from hard disk.
    4. Install the JRE/JDK you want for your test.
    5. Test.
    6. To test with another JRE/JDK, start over at step 1.

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 it usually does not work. Installing a new Java often makes the others 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.

I have found Opera will use the latest JVM installed, then later flip to track to the Java console when you turn off support for IE and Mozilla and then turn it back on again.

In Internet Explorer, you enable Java with: Tools ⇒ Internet Options ⇒ Advanced ⇒ Java Sun ⇒ Use Java (pick JRE).

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 homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/flipping.html J:\mindprod\jgloss\flipping.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.109]
You are visitor number 21,827.