MikkoP
MikkoP

Reputation: 646

Maven M2_HOME set to an invalid directory (Windows 7)

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.

Upvotes: 18

Views: 92627

Answers (16)

mainas
mainas

Reputation: 754

Quick Answer
Based on problems in using M2_HOME related to different Maven versions installed and to simplify things, the usage of M2_HOME has been removed and is not supported any more. Another important change for windows users: The usage of %HOME% has been replaced with %USERPROFILE%

More detailed answer
What you observed has always been a problem with maven. When you install two different versions in the same directory, the older version gets detected, while the newer one is not.
After Maven 3.3.9 was released, the Eclipse Aether project was retired and the code base was migrated to the Apache Maven project. The original goal for the 3.4.0 release was to replace Aether with the exact same code after migration to the Apache Maven project and then proceed with bug fixes to the resolver code as well as other areas of Maven. This never quite happened as intended and the decision was taken to forever burn the 3.4.x release line. The switch to 3.5 brought with it these changes

Upvotes: 0

There could be a possibility of having another version of maven installation at parallel location. In such case remove the unwanted one and reset the appropriate path against M2_HOME.

Upvotes: 0

rhinmass
rhinmass

Reputation: 194

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.

Upvotes: 2

Vidyasagar Gayakwad
Vidyasagar Gayakwad

Reputation: 81

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

Upvotes: 0

Ishara Samantha
Ishara Samantha

Reputation: 403

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

Upvotes: 0

user6470139
user6470139

Reputation:

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"

Upvotes: 0

sonikan
sonikan

Reputation: 11

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.

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97359

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.

Upvotes: 19

Ithar
Ithar

Reputation: 5425

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

Upvotes: 14

mark
mark

Reputation: 1

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.

Upvotes: 0

user6078975
user6078975

Reputation: 11

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.

Upvotes: 1

Kosmos
Kosmos

Reputation: 333

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

Upvotes: 0

romainb78
romainb78

Reputation: 91

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 !

Upvotes: 2

TomS
TomS

Reputation: 1169

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.

Upvotes: 18

Achraj
Achraj

Reputation: 381

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.

Upvotes: 38

Tai Nguyen
Tai Nguyen

Reputation: 165

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

Upvotes: 5

Related Questions