This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have both Java 1.4.2 and Java 1.5 installed on my Windows XP machine. How can I choose which version to use at run time? I have some applications which will run on Java 1.4 only.
Thanks, Cathy.
Sanjaya Sugiarto
Ranch Hand
Joined: Mar 25, 2004
Posts: 229
posted
0
Just adjust the classpath definition.
If you use Windows, than the classpath can be found: start -- settings -- system -- advanced -- environment variables than adjust the CLASSPATH definition. After that, you can check it: open the console, and type: java -version It will show the actual java version your system run
Note that the CLASSPATH setting will have no effect on which version of the runtime is used.
What you want to set is your PATH environment variable. It can be as simple as set PATH=C:\j2sdk1.4.2\bin;%PATH% for 1.4 or you might set it permanently in the Windows dialog.
To test which version JVM will be started, use: java -version To test which version compiler will be started, use: javac -J-version To determine the version at runtime, use: String version = System.getProperty("java.version");
In Windows, I have a batch file which has all of my jvm's listed. All are REMarked out except the one I want to run with. For example, to test myProgram, a jar file, in a JVM of my choice, I just remove the REM from the version of the JVM I want to use:
At the command prompt I just enter the name of the batch file to run:
Now it will launch in 1.4.2_04. No problem.
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
As Jeff shows, the best way to ensure which version of Java you run is by specifying the full path to the java executable. If you don't like the command line, I think you can set up your IDE to run with several different versions of the JDK. Unfortunately, I don't know the details as I haven't tried to do this before.
Layne
p.s. If you write and compile your programs with JDK 1.4, they should still run on JDK 1.5 as-is. However, the opposite isn't true unless you use the "-target 1.4" option.