Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows ignores JAVA_HOME: how to set JDK as default?

Tags:

java

windows

How do I persuade Windows to use the JDK instead of a JRE?

This question has been asked before, here and elsewhere:

How do I set the default Java installation/runtime (Windows)?

The trouble is that Windows ignores JAVA_HOME and it also ignores the fact that I made the JDK bin directory the first entry in the path.

When I run java -version from the command line, instead of invoking my JDK 1.6 installation, it runs the 1.7 JRE.

My guess is that this is a problem specific to 1.7, and Windows 7 is doing something it shouldn't with the registry.

Any ideas on how to fix this?

Edit: Oops. I wrote "first entry in the classpath" above, when I meant "path". Sorry.

like image 723
ccleve Avatar asked Mar 30 '11 21:03

ccleve


People also ask

Should JAVA_HOME point to JDK?

If you're doing any sort of development, or building with Maven or Ant, you need to point to the JDK (Java Development Kit) where utilities such as javac (the Java Compiler) reside. Otherwise, you can point to the JRE (Java Runtime Environment). The JDK contains everything the JRE has and more.

Why JAVA_HOME is not working?

Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.


2 Answers

On Windows, the java executable uses the Windows Registry to locate the default version of Java to run.

The copy of java.exe to run is found by using the PATH environment variable. Unless you take steps to change this, by default a copy will be found in the Windows directory. Since this copy isn't in a Java runtime directory, it locates one by looking at the registry.

So, you either need to modify the registry, or put the version of Java you want before the Windows directory in your PATH.

like image 171
erickson Avatar answered Sep 27 '22 21:09

erickson


In Windows 8, you may want to remove C:\ProgramData\Oracle\Java\javapath directory.

from path

It solved my issue.

like image 42
Arun Avatar answered Sep 27 '22 22:09

Arun