Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 870
MikkoP Avatar asked Dec 25 '12 21:12

MikkoP


People also ask

How do I set m2 home windows?

Set M2_HOME & PATHCreate an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH. Click OK, then Edit the 'Path' user variable to add M2_HOME\bin folder in it.

What should M2_HOME point to?

The M2_HOME is equivalent to JAVA_HOME and should point to the installation directory of Maven.

What is M2_HOME and Maven_home?

MAVEN_HOME is for Maven 1, M2_HOME is for Maven 2 and later. Maven 2 was a complete rewrite from Maven 1 and was not backwards compatible. Having the two different _HOME variables means it is possible to run both on the same machine. UPDATE. As of maven 3.5.

Is M2_HOME needed?

The home paths ( JAVA_HOME , M2_HOME ) are not mandatory but good to have. One of the advantages is: It helps you make changes at one place rather than search you way in the PATH variable when you install next version of Java or Maven.


2 Answers

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.

like image 139
Achraj Avatar answered Oct 07 '22 13:10

Achraj


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.

like image 41
khmarbaise Avatar answered Oct 07 '22 14:10

khmarbaise