• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to choose java version at run time

 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic