Maven M2_HOME set to an invalid directory (Windows 7)

匿名 (未验证) 提交于 2019-12-03 01:54:01

问题:

I've tried installing Maven to Windows 7 with poor results. Some basic info:

Maven installation directory: C:\Program Files\Apache Software Foundation\apache-maven-3.0.4 System Variable "M2_HOME": C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\ System Variable "Path" : %M2_HOME%apache-maven\src\bin;%JAVA_HOME%\bin

If I run mvn --version in the command path, I get the error message:

Please set the M2_HOME variable in your environment to match the location of the Maven installation

So at the moment the subdirectory for mvn is not set according to the instructions, which would be %M2_HOME%\bin. If I replace %M2_HOME%apache-maven\src\bin with that one, I get:

mvn is not recognized as an internal or external command, operable program or batch file

In the Maven installation directory (or in the zip-file) there is no \bin folder directly in apache-maven-3.0.4 and I wonder if there should be one?

I'm a complete novice to Maven, hopefully you guys can help.

By the way the Java command works from any directory, so I don't think that's the issue here, but I can't be sure.

回答1:

If your downloaded package apache-maven-3.3.9 does not contain a bin folder your download is wrong. you have to download a zip file which contains bin, boot, conf, lib folder otherwise there has gone something wrong. The downloaded file should have about 4.8 mb size. You can check the file via md5 or SHA1 checksums.



回答2:

In M2_HOME - set C:\apache-maven-3.0.4 i.e. path without bin. In PATH - set %M2_HOME%\bin i.e. with bin in path.



回答3:

In 3.3.1 *.bat files disappeared and just *.cmd files remained. .CMDs are the same as .BAT and some software expects them. I have renamed .CMDs to .BATs in order make it running under Netbeans. It caused "Maven M2_HOME set to an invalid directory". Copying .BATs to .CMDs (i.e. both were in the folder) solved the problem.



回答4:

In my case the setup was correct:

Windows System Variables:

  • M2 C:\dev\software\apache-maven-3.3.9\bin
  • M2_HOME C:\dev\software\apache-maven-3.3.9

Windows User variables:

  • %M2_HOME%\bin

But I had the same problem when there was two installation of maven even though all references was pointing to the latest version which in my case was 3.3.9. After deleting the older version the same command recognised maven.

BEFORE:

maven -v ERROR: M2_HOME is set to an invalid directory. M2_HOME = "C:\dev\software\apache-maven-3.3.9" Please set the M2_HOME variable in your environment to match the location of the Maven installation

AFTER:

maven -v Apache Maven 3.3.9 Maven home: C:\dev\software\apache-maven-3.3.9 Java version: 1.7.0_51, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.7.0_51\jre


回答5:

You need to download the Maven file that has the name "Binary zip". For example: http://mirrors.digipower.vn/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip



回答6:

I've the same problem on my computer and I resolved it :

  • I deleted the Maven directory and the Maven environment variables
  • I downloaded the binary zip archive on https://maven.apache.org/download.cgi
  • I unzipped it on C:\maven
  • I added new environement variable : C:\maven in M2_HOME, %M2_HOME%\lib in M2 and %M2% added in PATH

And it works !



回答7:

For me, the PATH variable had old version of maven. So I updated it. I should use %M2_HOME% but I had spelled out the path.



回答8:

Just now I faced the same issue. In my case the problem was that PATH wasn't set properly to include %M2_HOME%\bin. Once set properly, the problem was resolved.

When you face such issues, please print the value of PATH on the command line to ensure that it's properly picking up the values.



回答9:

All success after next steps.

  1. On http://maven.apache.org/download.cgi page from 4 variants need download binary file.

  2. Set environment variable (tip from @JamesB - https://stackoverflow.com/a/13093358/3941340):

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35

MAVEN_HOME=D:\software\apache-maven-3.0.4

PATH=%PATH%;%MAVEN_HOME%\bin;%JAVA_HOME%\bin

  1. Run mvn -version


回答10:

Had an old version of MVN in another directory that showed up in the search path. Removed the old version and everything worked. Used windows file search to scan the drive for all instances of "mvn" to find the old version.



回答11:

Add entire bin location to "PATH" environment variable Ex: C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin

No need of M2_HOME, M2.It worked for me

Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\XXXX>mvn -version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30) Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.9\bin.. Java version: 1.8.0_91, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_91\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"



回答12:

Check the System Variable M2_HOME and PATH in different maven locations.



回答13:

set 'M2_HOME' and 'PATH' in environment variables for your account, remove 'PATH' from system environment variables.



回答14:

Get rid of the env variable M2_HOME. It is not used by maven 3, and in fact, confuses it. If you had used it in your path, then either define the path to maven bin explictly, or change it to something else - like M3_HOME.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!