Maven Installation under Windows: “JAVA_HOME is se

2020-06-16 02:46发布

I'm new to Maven and I have downloaded the 3.0.5 version. I'm getting the following error:

JAVA_HOME is set to an invalid directory. please set the java_home variable in your environment variable to match the location of your java installation

Although, I see no error when I type javac or echo %M2_HOME% in the command prompt.

I have the following path variables set -

CLASSPATH - ;C:\Program Files (x86)\Java\jdk1.7.0_40\lib;
JAVA_HOME - C:\Program Files (x86)\Java\jdk1.7.0_40\bin
M2 - %M2_HOME%\bin
M2_HOME - C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5
MAVEN_OPTS - -Xms256m -Xmx512m
PATH - C:\Program Files\Java\jdk1.7.0_45\bin;C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin;

Can someone please help me?

标签: java maven
5条回答
爷、活的狠高调
2楼-- · 2020-06-16 03:23

To set JAVA_HOME

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_40

To add mvn to path

set PATH=%PATH%;C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin;

查看更多
Juvenile、少年°
3楼-- · 2020-06-16 03:25

JAVA_HOME should be set to jdk installation directory and not to the bin folder.

It should work, once the path is set properly.

查看更多
太酷不给撩
4楼-- · 2020-06-16 03:27

Read the official documentation. The Maven Installation Instructions for Windows are pretty simple to follow.

Windows

  • Unzip the distribution archive, i.e. apache-maven-3.2.1-bin.zip to the directory you wish to install Maven 3.2.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.2.1 will be created from the archive.

  • Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.2.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.

  • In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.

  • Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

  • In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.

  • In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_51 and that %JAVA_HOME%\bin is in your Path environment variable.

  • Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.

查看更多
欢心
5楼-- · 2020-06-16 03:33

Inside your system variables, set JAVA_HOME

JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45

and inside path, add these:

 C:\maven\bin;%JAVA_HOME%\bin;

The error is caused due to non readability of the java path .

查看更多
狗以群分
6楼-- · 2020-06-16 03:41
  • M2_HOME points to the directory where maven is installed.
  • M2 points to the bin directory under maven
  • JAVA_HOME points to the JDK directory installed on your system.

validate it again from below settings:

JAVA_HOME   - C:\Program Files\Java\jdk1.6.0_23
M2_HOME     - D:\Software\apache-maven-3.0.5
M2          - %M2_HOME%\bin
PATH        - %M2%;%JAVA_HOME%\bin
查看更多
登录 后发表回答