0
votes

I'm setting up Maven on Windows and I think everything is set up correctly, but I'm still getting the error "The JAVA_HOME environment variable is not defined correctly" when I run

mvn --version

In my environment variables, I have the following:

User variables

  • M2_HOME is C:\apache-maven-3.6.3
  • MAVEN_HOME is C:\apache-maven-3.6.3
  • JAVA_HOME is C:\Program Files\Java\jdk-11.0.2\bin

System Variables

  • JAVA_HOME is C:\Program Files\Java\jdk-11.0.2\bin

Inside System Variables, in my Path variable, I have:

  • C:\Program Files (x86)\Common Files\Oracle\Java\javapath

  • C:\ProgramData\Oracle\Java\javapath

  • C:\Program Files\Java\jdk-11.0.2\bin

  • C:\apache-maven-3.6.3\bin

Can't seem to figure out what's wrong with these environment variables such that Maven would be giving me that error. Any help would be greatly appreciated!

1
Remove the \bin from JAVA_HOME. JAVA_HOME should point to the root of a JDK, not to the executable directory. (The Path variable, however, should point to the bin directory of a JDK.) - VGR
your reference guide to set up your Java environment variables docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t - Player_Neo
Remove M2_HOME and MAVEN_HOME only the entry in PATH is needed and of course JAVA_HOME.. - khmarbaise
Thank you everyone! This solved it. - Tyler M.
As I mentioned only the entry into your PATH variable of the bin directory of the Maven installation and of course JAVA_HOME nothing more is needed. - khmarbaise

1 Answers

3
votes

Your JAVA_HOME is incorrect. JAVA_HOME should be "C:\Program Files\Java\jdk-11.0.2"

Remember to reopen new console after reset JAVA_HOME environment to apply new value.