1

I have created these variables with their respective values, but even after doing this, command prompt is not recognizing mvn command
System Variables:

  • name: M2_HOME
  • value: C:\Program Files\apache-maven-3.2.1

  • name: M2
  • value: %M2_HOME%/bin;

  • name: path
  • value: %JAVA_HOME%\bin; %M2_HOME%\bin;
Gab
  • 7,869
  • 4
  • 37
  • 68
manpreetSingh
  • 654
  • 4
  • 8
  • 20

10 Answers10

3

From Maven documentation page:

Maven, like many cross-platform tools, can encounter problems when there are space characters in important pathnames. The instructions below will remind you of this for several particular items.

You have Maven installed in C:\Program Files\apache-maven-3.2.1

Try to reinstall it to, for example, C:\maven, or change your current variable M2_HOME to C:\PROGRA~1\apache-maven-3.2.1

user11153
  • 8,536
  • 5
  • 47
  • 50
  • Pb pbly come from space indeed, but no need to reinstall just remove the space for the path using system folder names (C:\PROGRA~1\) or surround the path with double quotes – Gab Jun 11 '14 at 08:51
  • i have tried double quotes, but the output remains the same – manpreetSingh Jun 11 '14 at 08:58
  • @Gab Thanks, edited. @user3209819 Try `C:\PROGRA~1\apache-maven-3.2.1`, without quotes – user11153 Jun 11 '14 at 09:00
  • @Gab thanks a lot sir, it worked, its just the replacement of "Program Files" with "PROGRA~1", but what is the reason ? – manpreetSingh Jun 12 '14 at 15:09
  • the space character. please accept my answer to close the question; You should also upvote the one above cause the maven doc quote is appropriated – Gab Jun 12 '14 at 15:48
2

I had the same issue.

What I did to resolve this is creating M2_HOME & MAVEN_HOME. Also, edit Path variable value.

Created two System variables M2_HOME and MAVEN_HOME

enter image description here

enter image description here

enter image description here

New ->C:\Program Files\Apache Software Foundation\apache-maven-3.6.0\bin

where Apache Software Foundation is a folder I created to extract the apache-maven-3.6.0-bin.zip file.

Also, make sure Java is working fine and JAVA_HOME is properly set.

enter image description here

Sreelekshmi V
  • 151
  • 1
  • 2
  • 11
1

try :

  • to restart the command prompt
  • to start the command prompt with run/cmd instead of shift+right-click -"open command window here"
  • to put the system path between double quote to manage espace character
  • to replace C:\Program Files\ per C:\PROGRA~1\

edit

this is my own config :

MAVEN_HOME="C:\Program Files\apache-maven-3.2.1"

PATH=XXX;%MAVEN_HOME%\bin;XXX
Gab
  • 7,869
  • 4
  • 37
  • 68
  • please see my edit. Could you add the result of `echo %path%` command to your question if it's not fixed yet ? – Gab Jun 11 '14 at 12:57
  • the output of echo %path% is: C:\Program Files\Java\jdk1.7.0_51\bin;C:\PROGRA~1\apache-maven-3.2.1\bin – manpreetSingh Jun 11 '14 at 17:17
  • if you try to replace the Program Files of jdk path per PROGRA~1 ? Actually your mvn executable seems well added to the path and should be recognized – Gab Jun 12 '14 at 08:14
1

Hello I had the same problem and I figured it out that I was including some space characters on the "path" next to the ; just by removing the space character I was able to have everything working properly"

0

this is the settings for my maven.

name: MVN_HOME value: C:\Program Files\apache-maven-3.2.1

name: path -> add the following value(just the maven part) value: %JAVA_HOME%\bin;%MVN_HOME%\bin; -> this should have no spaces

user3720852
  • 13
  • 1
  • 5
0

I have a very difficult time to solve this problem. It did not work no matter how I set up the environment variables in the control panel of Win7.

My final solution is to set the variables via the cmd.

set M2_HOME "D:\Program Files\Maven\apache-maven-3.3.3"
set M2=%M2_HOME%\bin
set path=%path%;%M2%
shaosh
  • 657
  • 2
  • 8
  • 30
0

I think you have a typo:

change

name: M2
value: %M2_HOME%/bin;

to

name: M2
value: %M2_HOME%\bin;

if it doesn't work change %M2_HOME%\bin with the path. in this case:

C:\Program Files\apache-maven-3.2.1\bin

Paolo
  • 3,624
  • 2
  • 12
  • 13
0

Make sure to set the path under the System Variables and not User Variables.

  • No, User variable should work as well. Sometimes it is not possible to set System Variables (e.g. if you don't have Administrator privileges) – Alexander Jan 15 '19 at 14:22
  • When i had maven only set on the path in user variables it didn't pickup the version. When i added it to system variables instead, it worked for me. – Derrick Hall Jan 16 '19 at 07:18
  • maybe it worked for you, but probably because of something else. Maybe you logged out or rebooted the system and that's the reason, why this approach worked. Still this does not seem like a good answer to me. – Alexander Jan 16 '19 at 11:25
0

In my case, for reasons I cannot explain, it made a difference to windows 7 if the MAVEN_HOME environment variable was defined in "System Variables" vs "User Variables".

I originally had both JAVA_HOME and MAVEN_HOME as "User Variables" and "Java -version" worked but windows could not find mvn (My path variable looked like this in both cases "Path=C:\Program Files\Java\jre1.8.0_144\bin;E:\Clif\Java\apache-maven-3.6.0\bin;")

Once I changed both Environment variables from "User Variables" to "System Variables" windows was able to find mvn.

cliftonf
  • 67
  • 5
0

I was using %MAVEN_HOME% in the variable path and it was giving problem, even though echo %MAVEN_HOME% command was showing the right path.

I changed it to C:\Program Files\apache-maven-3.6.1\bin in the path (Depends on your version of-course) and it worked like a charm.

Io-oI
  • 2,514
  • 3
  • 22
  • 29
EggHead
  • 1
  • 3