• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use different java versions on my machine

 
nitude gupta
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have both 1.5 and 1.6 installed on my system.
I checked on console all programs were executed using 1.6 using command javac -version
But I want to run using 1.5...Is there any explicit cmd thorugh which I can change version at compile time..

Thank you in advance
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
If you are compiling from command prompt and your JDK 5 and 6 are in C:\Java5 and C:\Java6 respectively, then you can try this from command prompt
C:\Java5\bin\javac abc.java for 1.5
C:\Java6\bin\javac abc.java for 1.6 (or without it as its your default version)
I ***think*** it should work.

If using IDE, select the JDK of choice while creating project.

Jhakda
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nitude, Jhakda is right. You can install multiple versions of Java on your system at the same time. Usually setting the path environment variable to point to one of the version of java is the preferred way of using a specific java version but you can use the solution Jhakda gave too...
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to set the classpath pointing to the jdk directory which you want to use (1.5 or 1.6)
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshit Rastogi wrote:you need to set the classpath pointing to the jdk directory which you want to use (1.5 or 1.6)


Wrong. Don't set the classpath to jdk. It's the PATH system variable which points to bin directory of the jdk used.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You write something like
set PATH=C:\program files\java\jdk1.4.2_12\bin;%PATH%

at the command line (that syntax only works for Window: for *nix try export PATH=/usr/java/jdk1.4.2_12/bin:$PATH). I think it is "Set" but may be mistaken. Windows is case-insensitive, *nix is case-sensitive.
That should reset your PATH for that terminal/command prompt only. Putting a particular JDK first in the PATH forces the computer to use that particular version of the java.exe program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic