2

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?

Community
  • 1
  • 1
Aravind
  • 811
  • 4
  • 15
  • 33
  • 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](http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file) by specifiying the `java` part - it's a program after all. – Bagus Tesa Dec 30 '16 at 01:37
  • 2
    You seem to be confusing the JDK with the JRE. – Harry Johnston Dec 30 '16 at 01:53
  • What do `echo %PATH%` and `echo %JAVA_HOME%` say? – Stephen C Dec 30 '16 at 02: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 ...) – Stephen C Dec 30 '16 at 02:21

4 Answers4

12

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

10

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).

IqbalHamid
  • 1,966
  • 1
  • 15
  • 21
  • This was exactly the problem for me. What is the purpose of `javapath`? Why was it overriding my other PATH? – Hatefiend Aug 31 '20 at 22:10
  • Push your %JAVA_HOME%/bin to the top of the list in your environment variable setup under path WORKS ! , thanks – Jason Akon Sep 11 '21 at 03:18
7

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.

Abhijit Sarkar
  • 19,114
  • 16
  • 94
  • 178
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

  • 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. – Abhijit Sarkar Jan 16 '17 at 23:40
  • 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. – David Santiago Jan 21 '17 at 01:46
  • 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. – Abhijit Sarkar Jan 21 '17 at 04:24
  • You give me the reason: "In the IDE, I'd choose another installation from the drop down." – David Santiago Jan 21 '17 at 04:38