Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA_HOME and java -version

I'm using a Windows .bat script and I set JAVA_HOME as C:/Program Files/Java/jdk1.6.0_32 when I do a java -version, it still shows the 1.3

How can I fix this? What am I doing wrong?

like image 887
user1345883 Avatar asked May 21 '12 14:05

user1345883


People also ask

Does Java use JAVA_HOME?

The JAVA_HOME environment variable is not actually used by the locally installed Java runtime. Instead, other programs installed on a desktop computer that require a Java runtime will query the OS for the JAVA_HOME variable to find out where the runtime is installed.

What is Java home and Java path?

JAVA_HOME is an Environment Variable set to the location of the Java directory on your computer. PATH is an internal DOS command that finds the /bin directory of the version of Java that you are using.

What is difference between JAVA_HOME and path?

PATH values: notice how the directory we set for JAVA_HOME is the JDK installation root whereas for PATH we add the bin directory within the JDK installation. Take care to set these up correctly otherwise you'll have problems later on.

How do I set JAVA_HOME?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.


2 Answers

For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath; was added by java windows install before my %JAVA_HOME%\bin;. So I'd echo %JAVA_HOME% pointing to a JDK7 and java -version showing jdk8.

I'd to put %JAVA_HOME%\bin; before C:\ProgramData\Oracle\Java\javapath; so that java -version displays jdk7.

like image 97
TheBakker Avatar answered Oct 18 '22 14:10

TheBakker


Try %JAVA_HOME%\bin\java -version

If you modify JAVA_HOME, it's usually better to invoke java with an absolute path (using JAVA_HOME) because the new binary is probably not in the path (and then Windows will load the wrong binary).

like image 23
Aaron Digulla Avatar answered Oct 18 '22 13:10

Aaron Digulla