0

When I run java -version from the command line it returns jre1.8.0_91. I've used setx from the command line and edited the environment variable for JAVA_HOME. The command line seem to be overridden or ignoring the environment variable. All JDK needing commands like mvn error with: "you must set JAVA_HOME to a jdk not a jre"

JAVA_HOME=C:\Program Files\Java\jdk-11.0.6;C:\Program Files\Java\jdk1.8.0_241

Oozeerally
  • 842
  • 12
  • 24
Sherum
  • 63
  • 7

1 Answers1

4

JAVA_HOME should point to one directory only, you can't have two there. That's why your Maven does not work. Fix that and Maven should work.

java -version output is not directly related, that command does not use JAVA_HOME but PATH (but as noted in the comments, it is possible that PATH refers to JAVA_HOME, so in that case they are indirectly related).

eis
  • 51,991
  • 13
  • 150
  • 199
  • 1
    It is normal practice though to prepend `%JAVA_HOME%\bin;` to your `PATH` – g00se Aug 11 '21 at 15:06
  • I do not have a jre 11 installed. I removed the jdk1.8.0_241 entry path and got the same error, then removed jdk11 entry path and replace the previous and it worked as expected. Not sure if this would have worked with jdk11 if the jre was also installed. Running java -version does reflect updated _241 build – Sherum Aug 11 '21 at 15:14
  • @g00se yes, but usually there is something with java already in PATH before that one – eis Aug 11 '21 at 15:40
  • @Sherum maybe you removed it wrong. Did you remember to remove `;` also from JAVA_HOME value? – eis Aug 11 '21 at 15:42
  • *@g00se yes, but usually there is something with java already in PATH before that one* @ais You need to read my comment more carefully, in particular the 7th word ;) – g00se Aug 11 '21 at 15:54
  • @g00se ok, misread prepend as append. I think it is more common to append it rather than prepend. If it is added at the beginning then you're right that it matters. – eis Aug 11 '21 at 16:04
  • @eis Yes. I specifically said that for the reason *you* gave – g00se Aug 11 '21 at 16:07
  • I reconfigured for jdk 11 using setx and mvn worked correctly. i cannot be certain if I had a trailing ; causing the issue. – Sherum Aug 11 '21 at 17:22
  • @Sherum if you consider this answer has resolved your problem, consider accepting the answer (the tick box beside the answer) – eis Aug 12 '21 at 12:51