1

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!

Tyler M.
  • 115
  • 1
  • 1
  • 11
  • 8
    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 Feb 06 '20 at 01:07
  • 1
    your reference guide to set up your Java environment variables https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/ – Player_Neo Feb 06 '20 at 02:32
  • Remove M2_HOME and MAVEN_HOME only the entry in PATH is needed and of course JAVA_HOME.. – khmarbaise Feb 06 '20 at 07:49
  • @khmarbaise You're saying that I only need to reference maven in my Path system variable, and so don't need those references in my user variables? – Tyler M. Feb 06 '20 at 15:52
  • 1
    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 Feb 06 '20 at 16:21

1 Answers1

4

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.

Kevin Le
  • 266
  • 1
  • 5