14 Replies Latest reply: Apr 20, 2007 5:06 AM by 807596 RSS

    Running Multiple JDKs on the Same Machine

    807596
      I've been developing with the 1.4.2_07 JDK, but my company is moving to the 1.5.0 JDK as the new standard for our product. Of course, we're going to continue supporting the 1.4.x JRE as a deployment platform for the near term.

      As a developer, I'm going to need to have both JDKs installed, side-by-side so that I can use both of them in my development/testing cycles. So I just downloaded and installed the 1.5.x JDK, and I defined the following environment variables:

      JAVA_HOME_1_4 = C:\j2sdk1.4.2_07
      JAVA_HOME_1_5 = C:\Program Files\Java\jdk1.5.0_02
      JAVA_HOME = %JAVA_HOME_1_4%

      In theory, I should now be able to switch JDKs just by changing my JAVA_HOME variable to %JAVA_HOME_1_5%.

      Easy as pie.

      Unfortunately, that doesn't work, because the 1.5 JDK installs a number of registry keys which hard-code the current java version. So, even when I have JAVA_HOME set up to point to the 1.4.x JDK, running "java -version" at the commandline indicates that the 1.5 java is being called.

      I'd like to suggest to Sun that, in the future, there should be a generic, version-independent launcher that reads in the JAVA_HOME variable at runtime and calls the appropriate binaries and the appropriate runtime libraries.

      Having to futz around with the registry every time I want to switch my development environment is a big hassle.

      --BenjiSmith                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
        • 1. Re: Running Multiple JDKs on the Same Machine
          807596
          So, even when I have JAVA_HOME set up to point to the 1.4.x JDK,
          running "java version" at the commandline indicates that the 1.5 java is being called.
          That depends on which java is contained in PATH.
          I am happily using several JDK's on the same box, either adjusting PATH accordingly or calling javac, java, javap with full path names from wrapper scripts.
          • 2. Re: Running Multiple JDKs on the Same Machine
            807596
            So, even when I have JAVA_HOME set up to point to
            the 1.4.x JDK,
            running "java version" at the commandline indicates
            that the 1.5 java is being called.

            That depends on which java is contained in PATH.
            I am happily using several JDK's on the same box,
            either adjusting PATH accordingly or calling javac,
            java, javap with full path names from wrapper scripts.
            I have JDK 1.3 and 1.4 on my machine. Both my PATH and JAVA_HOME point to 1.3 JDK. However, when I give the command java -version, I get back, java version "1.4.2_07".
            • 3. Re: Running Multiple JDKs on the Same Machine
              796365
              However, when I give the command java -version, I get back, java version "1.4.2_07".
              Which is because there is a copy of java.exe in a directory that is listed in your PATH variable prior to (left of) where you have the reference to 1.3

              Probably in C:\windows\system32 (assuming Win XP).

              With multiple version installed, the safest way to execute java is, as was previously stated, via a shell script or .bat file that correctly specifies the paths(s) to the executables.
              • 4. Re: Running Multiple JDKs on the Same Machine
                807596
                I've been developing with the 1.4.2_07 JDK, but my
                company is moving to the 1.5.0 JDK as the new
                standard for our product. Of course, we're going to
                continue supporting the 1.4.x JRE as a deployment
                platform for the near term.

                As a developer, I'm going to need to have both JDKs
                installed, side-by-side so that I can use both of
                them in my development/testing cycles. So I just
                downloaded and installed the 1.5.x JDK, and I defined
                the following environment variables:

                JAVA_HOME_1_4 = C:\j2sdk1.4.2_07
                JAVA_HOME_1_5 = C:\Program Files\Java\jdk1.5.0_02
                JAVA_HOME = %JAVA_HOME_1_4%

                In theory, I should now be able to switch JDKs just
                by changing my JAVA_HOME variable to
                %JAVA_HOME_1_5%.

                Easy as pie.

                Unfortunately, that doesn't work, because the 1.5 JDK
                installs a number of registry keys which hard-code
                the current java version. So, even when I have
                JAVA_HOME set up to point to the 1.4.x JDK, running
                "java -version" at the commandline indicates that the
                1.5 java is being called.

                I'd like to suggest to Sun that, in the future, there
                should be a generic, version-independent launcher
                that reads in the JAVA_HOME variable at runtime and
                calls the appropriate binaries and the appropriate
                runtime libraries.

                Having to futz around with the registry every time I
                want to switch my development environment is a big
                hassle.

                --BenjiSmith
                I've tried the same approach, but abit different
                first - deleted java.exe and javaw.exe from %SystemRoot%\system32
                Then set the following (All vars are system ones)
                JAVA_HOME=D:\sun\jdk1.5.0_04
                JAVA_HOME_1.4=D:\sun\j2sdk1.4.2_08
                JAVA_HOME_1.5=D:\sun\jdk1.5.0_04
                JAVA_HOME_BIN=%JAVA_HOME%\bin
                PATH=%JAVA_HOME_BIN%;...
                Now by switching JAVA_HOME we should get it right
                but,
                it appears that xp recognizes the new values for vars only upon rebooting.
                Also, you can see all current vars by typing set in cmd
                More over, I thought that maybe it'd work if I just simply logout/login back, and it did but strangely the var while JAVA_HOME showed a new value, JAVA_HOME_BIN had the previous one.

                HMM...
                • 5. Re: Running Multiple JDKs on the Same Machine
                  807596
                  No, I was wrong, the env vars are become immediately available, without any reboot.
                  What happened was that I've tried to use <set> command of cmd having not closed the console, thus getting the old values.
                  • 6. Re: Running Multiple JDKs on the Same Machine
                    807596
                    I still don't believe that it's possible to switch back and forth between Java versions.

                    On my system, the registry contains hundreds of hard-coded path names pointing to my Java 1.5 installation. The registry doesn't contain any links to my Java 1.4.2 installation.

                    Here are some of the more offensive looking registry keys where I've found hard-coded paths to the Java 1.5 install dir:

                    HKEY_CLASSES_ROOT\Applications\javaw.exe\shell\open\command
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in\1.5.0_05\JavaHome
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5.0_05\JavaHome
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5.0_05\RuntimeLib
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_02\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_03\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_04\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.2\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.2.0_01\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.5.0_05\Home
                    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\AdvancedOptions\JAVA_SUN\SELECT\RegPath
                    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\javaws.exe
                    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\javaws.exe\Path
                    • 7. Re: Running Multiple JDKs on the Same Machine
                      796365
                      I still don't believe that it's possible to switch back and forth between Java versions.
                      Applets and other programs that use the browser use these entries. Browsers can have only one actove JRE plug-in active at a time. This is controllable by entries in the Java Control Panel.

                      Webstart has it's own use for these entries.

                      Java applications started from the commandline (with "java. . .") don't use these entries at all. Version control is accomplished by starting the desired version of java.exe or javaw.exe, specifying the path to the executable - as stated previously.
                      • 8. Re: Running Multiple JDKs on the Same Machine
                        807596
                        All,

                        Low tech solution...

                        I have been wanting to switch version for a while, and I have tried all of the above. I have found an easy way to switch java versions.

                        The java version in your system folder redirects you to the correct java jre installed in 'Program File\java\...'

                        1) Just rename the current/latest jre that is being used to original_(version name).
                        2) Then copy the older version to the same folder creating a file called "Copy_of_(older version)". (Since that version currently exists in the same folder)
                        3) Then rename the "Copy of_.." to the latest version name. Since the directory tree is the same everything works.

                        I have a replaytv 5000 model and use I DVARCHIVE, which requires jre_1.4.2. My work laptop has jre 1.5.0_05 installed, and I need to use it for other apps also. Now I can switch.

                        Hope this helps...

                        -Ed
                        • 9. Re: Running Multiple JDKs on the Same Machine
                          jwenting
                          However, when I give the command java -version, I
                          get back, java version "1.4.2_07".

                          Which is because there is a copy of java.exe in a
                          directory that is listed in your PATH variable prior
                          to (left of) where you have the reference to 1.3

                          Probably in C:\windows\system32 (assuming Win XP).
                          where you can safely delete java.exe and javaw.exe if your path is set up to point to an existing %JAVA_HOME%\bin
                          • 10. Re: Running Multiple JDKs on the Same Machine
                            807596
                            i have several jdk versions installed on my PC.
                            I want to get rid of all of them and install only the latest one..

                            how can i do this?

                            i seem to have the same problem too and i think mine is complicated by the fact that i have installed several jdk versions.

                            thanks
                            • 11. Re: Running Multiple JDKs on the Same Machine
                              807596
                              Rather than deleting or renaming Windows/System32/java.exe try putting your "default" jdk as the first entry in your system's %PATH% variable (or at least before the %SystemRoot%\system32 entry). That way windows will resolve to the first instance of java.exe.
                              • 12. Re: Running Multiple JDKs on the Same Machine
                                807596
                                If you're using myEclipse, you should be able to switch compiler by going to Window->Preferences->Java->Compiler. There's a "Compiler Compliance level" dropdown that lets you select versions of compilers you want to use. I have Eclipse 3.1.0 version right now. Hope this helps
                                • 13. Re: Running Multiple JDKs on the Same Machine
                                  807596
                                  All,

                                  Low tech solution...

                                  I have been wanting to switch version for a while,
                                  and I have tried all of the above. I have found an
                                  easy way to switch java versions.

                                  The java version in your system folder redirects you
                                  to the correct java jre installed in 'Program
                                  File\java\...'

                                  1) Just rename the current/latest jre that is being
                                  used to original_(version name).
                                  2) Then copy the older version to the same folder
                                  creating a file called "Copy_of_(older version)".
                                  (Since that version currently exists in the same
                                  folder)
                                  3) Then rename the "Copy of_.." to the latest version
                                  name. Since the directory tree is the same everything
                                  works.

                                  I have a replaytv 5000 model and use I DVARCHIVE,
                                  which requires jre_1.4.2. My work laptop has jre
                                  1.5.0_05 installed, and I need to use it for other
                                  apps also. Now I can switch.

                                  Hope this helps...

                                  -Ed
                                  I tried the method but it did not work.
                                  • 14. Re: Running Multiple JDKs on the Same Machine
                                    807596
                                    hmmmmm yas Mr. gorecki is right.....the best soultion ha has given