Reputation: 8704
I have 2 Java installed on my machine. 1.5 and 1.6. For the project, I need 1.5. I have set all of my path variables to appropriate i.e.
echo %JAVA_HOME%
<PATH_TO_1.5_JDK>
which is what i want .. but when i do
java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)
why java v 6 is being picked for java -version
command ?
UPDATED
I have already checked the %PATH%
variable and the only java version that appears in path is 1.5. I am referring to SYSTEM VARIABLES
variable here and I am using Win7
Upvotes: 3
Views: 10586
Reputation: 11
I had a similar problem that I fixed:
Path was not changing because user-specific JAVA_HOME
was pointing to some wrong Java version.
Typing "edit environmental variables for your account" in run for Windows, I saw another JAVA_HOME
in user variables. I removed it, and then the right Java version was used.
Upvotes: 1
Reputation: 1
I had the same problem using Java 7 and Java 8.
Solution: Remove from the PATH variable (System variables) the following entry :
c:\ProgramData\Oracle\Java\javapath\
Upvotes: 0
Reputation: 1238
Java 6 is picked because it comes first in you PATH environment variable. It has nothing to do with JAVA_HOME variable, until and unless you specify you PATH variable using JAVA_HOME variable
Setting a new USER variables PATH as JAVA_HOME\bin, will solve your problem
Upvotes: 7
Reputation: 718798
AFAIK, none of the HotSpot Java commands use JAVA_HOME for anything:
Commands such as java
and javac
are located based on the PATH variable, on Windows, UNIX, Linux, and BSD-based operating systems such as MacOS. Location of commands via the PATH is a typically command shell and/or OS function.
The JAVA_HOME variable is used by some 3rd-party tools such as Ant, Maven, Tomcat and so on to locate the Java installation to be used. But other tools ignore JAVA_HOME and either use an application specific configuration mechanism (e.g. Eclipse), or some shell stuff to determine the installation location from (for example) the location of the java
command found via the PATH
.
Upvotes: 0
Reputation: 11298
JAVA_HOME is differ from PATH where the java executes from.
Read this you will get clear idea
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
Upvotes: 1
Reputation: 59617
If you're running the java
command on the command-line, the important environment variable is %PATH%
: if the path to the JDK-1.6 bin directory precedes the path to the 1.5 bin directory on your path, then running java
on the command line will use the 1.6 version.
The JAVA_HOME
environment variable is used by various other programs to locate the JDK, such as ant, some IDEs, and third-party libraries.
If you're using a specific IDE for your project then you'll need to find out how it locates the JVM. If you'll be compiling on the command line, then adjust your PATH
so that the 1.5 install precedes the 1.6 install, or use full paths to the compiler and VM.
Upvotes: 3