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 "
C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\ System Variable "
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.
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.
M2_HOME - set
C:\apache-maven-3.0.4 i.e. path without
PATH - set
%M2_HOME%\bin i.e. with
bin in path.
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.
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:
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.
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
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
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
- I added new environement variable :
%M2% added in
And it works !
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.
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.
All success after next steps.
On http://maven.apache.org/download.cgi page from 4 variants need download binary file.
Set environment variable (tip from @JamesB - https://stackoverflow.com/a/13093358/3941340):
- Run mvn -version
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.
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"
Check the System Variable M2_HOME and PATH in different maven locations.
set 'M2_HOME' and 'PATH' in environment variables for your account, remove 'PATH' from system environment variables.
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.