5 Replies Latest reply: Jan 30, 2013 12:10 PM by rp0428 RSS

    Switching between different versions of Java

    987842
      I have multiple versions of Java(Java 5, Java 6 and Java 7) on my machine. I want to run an older version of java(eg: Java 5). I have tried setting the JAVA_HOME = Java 5 and added the JAVA_HOME to Path. I have also brought up the Java Control Panel made sure that only the Java 5 is checked in the user tab, in the system tab nothing is checked cause only Java 7 is listed and the Add button is disabled. Still when I run java -version in the command prompt it shows the java version as Java 7. javac -version shows the expected Java 5.

      I think uninstalling and re installing the different versions of Java my clear my issue but I don't want to keep doing this. Does anyone know where I could be going wrong.
        • 1. Re: Switching between different versions of Java
          TPD-Opitz
          Welcome to the forum.

          This is not a java qesion tough and you should rather ask Bill about whats goin on...

          But wee need some more information about you system so that we may come up with a solution:

          What's your windows version?
          Did you reopen your command line bewtween the changes?
          If so, did you start it from another program like TotalCommander/FreeCommander? Did you restart that one too?
          What is the output of <tt>set path</tt>, is there only one path to java in there and if not, which one comes first?

          bye
          TPD
          • 2. Re: Switching between different versions of Java
            939520
            Also, try copy/paste the PATH to notepad so you can view the entire length of the value.
            Check it to ensure you only have terms something like %JAVA_HOME%/bin and not the hard coded value for JAVA_HOME, something like C:/Java/jre5/bin.
            However, if you see terms such as C:/orcale/jre4, leave it alone. That's the version Oracle wants.
            • 3. Re: Switching between different versions of Java
              rp0428
              >
              I have multiple versions of Java(Java 5, Java 6 and Java 7) on my machine. I want to run an older version of java(eg: Java 5). I have tried setting the JAVA_HOME = Java 5 and added the JAVA_HOME to Path. I have also brought up the Java Control Panel made sure that only the Java 5 is checked in the user tab, in the system tab nothing is checked cause only Java 7 is listed and the Add button is disabled. Still when I run java -version in the command prompt it shows the java version as Java 7. javac -version shows the expected Java 5.

              I think uninstalling and re installing the different versions of Java my clear my issue but I don't want to keep doing this. Does anyone know where I could be going wrong.
              >
              You need to do what people have been doing since the birth of the PC.

              Create a batch file for each version of Java and put the batch files in a folder that is on your PATH.

              In the batch file set the JAVA_HOME and the PATH appropriate for that version of Java.

              You can also add parameters to the batch file. You might add one parameter for the name of a class to run and one parameter for the classpath.

              Then in a command prompt just type the name of the batch file for the version of Java that you want to run and any parameters that are needed.
              • 4. Re: Switching between different versions of Java
                BIJ001
                Create a batch file for each version of Java and put the batch files in a folder that is on your PATH.
                That is what I do but then instead of setting with JAVA_HOME etc. I invoke the command using its full path name.


                For example I have a wrapper script java16.bat (put onto the PATH) with the contents:
                "C:\Program Files\Java\jdk1.6.0_23\bin\java" %*
                • 5. Re: Switching between different versions of Java
                  rp0428
                  >
                  That is what I do but then instead of setting with JAVA_HOME etc. I invoke the command using its full path name.

                  For example I have a wrapper script java16.bat (put onto the PATH) with the contents:
                  "C:\Program Files\Java\jdk1.6.0_23\bin\java" %*
                  >
                  That is not the preferred way to use batch files for processing. For one thing that will leave JAVA_HOME pointing to some unknown version of Java.

                  You would have multiple wrapper scripts (for 1.4, 1.5, 1.6, 1.7) but JAVA_HOME only points to one of them. What happens when you run your 1.4 batch script with the HOME pointing to 1.6?

                  A main goal of the batch file is to be able to CONTROL the environment it is operating in. Any, and all, environment variables that are necessary to the proper functioning of the batch file should be explicitly set in the batch file itself.

                  You should explicitly set PATH, JAVA_HOME, ORACLE_HOME, temp directory, log directory, etc.: that is, ALL variables that the batch file commands are dependent on.

                  Your method creates an unnecessary dependency in your batch file and the version mismatches that it makes possible can cause problems that can be extremely difficult to diagnose and fix.