Apache Maven install “'mvn' not recognized

2019-01-13 20:43发布

I've followed the official installation instructions here for Windows XP. But sometimes when I execute mvn --version, I receive the error message,

'mvn' not recognized as an internal or external command

I've even rebooted my machine a couple times, but the OS does not always recognize the maven command. But when I execute either, cd %M2_HOME%, or cd %M2% it brings me to the installation directory. I've also made sure to add the user variable M2 to the Path system variable.

So, what gives?

28条回答
\"骚年 ilove
2楼-- · 2019-01-13 21:17

Assuming you've created the variable path for maven as follows:

Under System path, click new then edit as follows:

Variable name: MAVEN_HOME

Variable value: C:\Program Files\apache-maven-3.5.3\bin

Then continue with these instructions:

Under System Path, update variable path by clicking on edit and add:

C:\Program Files\apache-maven-3.5.3\bin;

immediately after:

C:\Program Files\Java\jdk\1.8.0_161\bin;

remember to add semi-colon ; after \bin as included above and then run your cmd prompt and type:

mvn -v 
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-13 21:18

I had this same problem, restart the command prompt and then check try mvn --version. It was probably set and working the whole time but command prompt needed to be restarted to be able to access the new system variable.

查看更多
叛逆
4楼-- · 2019-01-13 21:18

Installtion Steps

  1. Download Binary zip archive or tar.gz.
  2. Copy in the respective folder. Example - C:\apache-maven-3.3.9
  3. Add Variable (either user or system) M2_HOME = C:\apache-maven-3.3.9
  4. Add Variable (either user or system) MAVEN_HOME = C:\apache-maven-3.3.9
  5. Update Variable PATH with C:\apache-maven-3.3.9\bin
  6. Open CMD and Type mvn -v or mvn --version it should give the below response

C:\Users\XXXXXXX>mvn --version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4 7+05:30) Maven home: C:\apache-maven-3.3.9 Java version: 1.8.0_40, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_40\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 8", version: "6.2", arch: "amd64", family: "dos"

**Make sure all variables have correct values using echo %M2_HOME% on CMD

查看更多
何必那么认真
5楼-- · 2019-01-13 21:19

Way around would be moving M2 from user variables to system variables

查看更多
孤傲高冷的网名
6楼-- · 2019-01-13 21:21

Heres what i did wrong:

1) make sure its NOT in a [C:\Program Files (x86)] it should be in [C:\Program Files] i am not 100% if that could break it but you never know.

2) There were 3 things i needed to do in my Environment Variables to get it to work

  1. Create a user var like this [ M2 = %M2_HOME% ]
  2. Create a user var like this [M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-3.2.2]
  3. Edit the PATH to [What ever is already in here +];%M2%
查看更多
不美不萌又怎样
7楼-- · 2019-01-13 21:21

A temporary work around would be to set the path from the terminal itself. Worked for me after that. Running as administrator also works. Both M2 and M2_HOME are already set as system variables in my case.

查看更多
登录 后发表回答