6

Previously I am using Java 1.8 in my machine. But now i need to use Java 1.6. So I changed the below values in system environment variables.

JAVA_HOME

U:\POC\jdk1.6.0_31

PATH

U:\POC\jdk1.6.0_31\bin\ or %JAVA_HOME%/bin

Also I restarted my system

Even after that it is displaying java version as 1.8 in my command prompt.

command Prompt

Can anyone advice on how to resolve this issue?

4
  • don't, you did not change java version that way. if you want the old one, just install it. you can have several java runtime in a single machine, but only one will be ran as main java runtime. and if you want to run something on older jvm you ought to run java jar command by specifiying the java part - it's a program after all. Commented Dec 30, 2016 at 1:37
  • 2
    You seem to be confusing the JDK with the JRE. Commented Dec 30, 2016 at 1:53
  • 1
    What do echo %PATH% and echo %JAVA_HOME% say? Commented Dec 30, 2016 at 2:17
  • "But now i need to use Java 1.6." - Seriously, you should try to avoid that. Java 1.6 has not received public security patches for > 3 years. You are potentially putting your system security at risk by using Java 1.6. (Unless you have an extended maintenance contract with Oracle ...) Commented Dec 30, 2016 at 2:21

6 Answers 6

24

when latest version is installed in system it automatically set javapath in environment variable like "C:\ProgramData\Oracle\java\javapath". Remove this from environment variables.enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

You saved my day
14

This suggestion may seem obvious, but I urge you to carefully consider this advice.

I have encountered this issue before, and frequently, it has been due to an overlooked entry within the long list of items making up the Windows Path. It is often an path entry where it is not immediately obvious that any of the java executables (javaw.exe, javaw.exe or javaws.exe) may reside. A common culprit is C:\ProgramData\Oracle\Java\javapath

You will therefore need to push upwards, your desired java/bin path above these. If in doubt, push it right to the top!

In the unlikely event that this does not work, then try making changes from within the java admin console (Control Panel --> Java --> Java tab --> View Button).

3 Comments

This was exactly the problem for me. What is the purpose of javapath? Why was it overriding my other PATH?
Push your %JAVA_HOME%/bin to the top of the list in your environment variable setup under path WORKS ! , thanks
This really worked, hmmm. But it worked.
8

I've not used Windows in a long time but I remember that there are 2 sections of environment variables. One system scope, and the other user scope.

  1. Check that nothing in the system scope is defining a JAVA_HOME.
  2. Like @Stephen C said, post the output of echo %PATH% and echo %JAVA_HOME%.
  3. Check that nothing comes before %JAVA_HOME%/bin in the path that may contain the java executable. Things like Oracle client come with Java. You can always put %JAVA_HOME%/bin in front of the path instead of at the end.

@David Santiago's answer is a bad idea. If you let the IDE do your job, you won't be able to troubleshoot when there is a problem.

Comments

1

I recently ran into this as I have added in JAVA 9, 11, and 17 along with my previous JAVA 6, and 8 versions.
I incorrectly assumed that env variables hadn't changed with the newer releases, but I was obviously wrong.

When I ran java -version it returned JAVA 9 and javac -version returned JAVA 17. So, I incorrectly tried to add a %JAVA_HOME% variable, as I had always done in pre-JAVA 8 versions under the Windows Environment Settings. However, despite moving that addition to the front of the PATH, it didn't change anything!

This article explains the issue: Java SE 8 Update 171 Uses Different Windows Path (Doc ID 2412304.1), however it doesn't give any solutions.

The path to this Windows folder is:

C:\ProgramData\Oracle\Java\javapath

Notice it is under a ProgramData folder, not Program Files. Moreover, it has been prepended to PATH under the Windows env settings. This folder is where java has 3 symbolic links set that will override the PATH changes you make and sure enough it was pointing to the JAVA versions I returned from -version on java and javac. Even if I tried to set a JAVA_HOME as the first entry in path, it still didn't work!

I found two solutions here at: JDK 8 and C:\ProgramData\Oracle\Java\javapath

How to switch JDK version in cmd more flexibly You can either prepend your own directory to the PATH to overwrite the Oracle one, or follow the convention to append to the end of PATH variable like always did. I prefer the second one, here is how to do it.

The second solution uses two batch files with a env variable JAVA_HOME setting similar to what I had always used.

Comments

0

The system displays the latest version installed on the system. That's informative only, that should not worry you.

If you are going to use version 6.0_31 of the Java JDK you only have to configure that in your IDE (Eclipse, Netbeans, IntelliJ IDEA, whatever) to compile using that version.

Example

4 Comments

This is not an answer to what the OP is asking. His path shows Java 8, which is indeed an issue if he tries to build from command line.
Thanks for your comment, the correct answer depends on the perspective of the problem. Display a console data (path) or compile in an IDE. I do not agree with your idea, because it refers to configure an absolute route discarding other possible versions. Also the question refers, "But now I need to use Java 1.6.". What if you want to use another JDK version? Best Regards.
You obviously don't have to agree with me, that's fine. In order to switch Java used by the cmd, OP would change his JAVA_HOME value. In the IDE, he'd choose another installation from the drop down. There's no software that can dynamically change Java by reading the user's mind.
You give me the reason: "In the IDE, I'd choose another installation from the drop down."
-1

On command prompt use these commands to set envirnment variables

JAVA_HOME=C:\Program Files\Java\jdk-11.0.17

set PATH=%JAVA_HOME%\bin;%PATH%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.