• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to choose java version at run time

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Get off me! Here, read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic