Search code examples
javamavenpathenvironment-variablesjava-home

Maven JAVA_HOME environment variable is not defined correctly, but it is


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!


Solution

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