2

I note to begin with that a very related question has been asked before, but the answer was to restart the system which does not work for me. Here is that link if anyone is interested:

WINDOWS 10 JAVA_HOME is not working

Also, there are several similar discussions about Path, and the answers seem to involve the order in which entries appear in the path, or a registry reset, however that does not appear to be the case here, since my working and non-working solution use the same order and the same registry settings. I did not list these since there are several.

But my case is that I have set JAVA_HOME:

enter image description here

And then I have used JAVA_HOME in Path (at the bottom, not the top):

enter image description here

And then javac -version fails at the command line:

enter image description here

But if I replace JAVA_HOME with its exact contents in Path:

enter image description here

Then javac -version works:

enter image description here

So, seemingly a pointless question since I can make it work. However, I am wondering why partly in the interest of knowing what is going on and partly in the interest of knowing if JAVA_HOME will fail if used elsewhere.

RCM
  • 333
  • 2
  • 8
  • You need to add `JAVA_HOME\bin` to path. `javac` is not in the top level dir – flakes Nov 24 '18 at 01:51
  • @flakes but isn't %JAVA_HOME%\bin the last line of my path (second image)? – RCM Nov 24 '18 at 01:52
  • Also, I did try JAVA_HOME (followed by \bin) without the enclosing %% as in my example and this failed too, but again, the simple path contents of JAVA_HOME (followed by bin of course) does work ... – RCM Nov 24 '18 at 02:04
  • 2
    @RCM define both variables in the same scope, not system vs. user. – Martin Zeitler Nov 24 '18 at 02:04
  • In `cmd` type `SET` and see what the path is set to. maybe it's invalid at some point. Could also be that the user variable isnt getting considered in the system vars. iirc if you create a path in user vars it will get appended to the system – flakes Nov 24 '18 at 02:04
  • 1
    It does appear to be that the JAVA_HOME has to be a system variable not a user variable. I guess maybe that's obvious?! Not to me, lol! Martin Zeitler since you were first to say this, do you want points for the answer? Write it and I'll choose you. Otherwise in a day or so I'll write it just so others can easily find it. – RCM Nov 24 '18 at 02:20

1 Answers1

1

If your %JAVA_HOME% variable is in the user variables scope, you must be logged in from that specific user account (*Checked on Windows 7).

Or as Martin Zeitler has mentioned in the comments, best option is to put both variables in the same scope.

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • OK, I will accept this one since Martin Zeitler never came back and wrote his comment as an answer...even though he was the first to point out what I think is the main issue...JAVA_HOME must be a system variable (not a user variable) . – RCM Nov 29 '18 at 02:30