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条回答
smile是对你的礼貌
2楼-- · 2019-01-13 21:14

I was facing the same issue while executing the command mvn -version; however, I checked I had also set the mvn options in the environment variables setting, which gave me some Heap memory issue on the command prompt. So, I removed the maven options that I had set and then it worked fine for me.

查看更多
干净又极端
3楼-- · 2019-01-13 21:15

Had the same problem,

mvn --version

worked but

maven --version

did not. I prefer using 'mvn' over 'maven' anyway so all is well. I also logout/login in to be sure.

查看更多
Juvenile、少年°
4楼-- · 2019-01-13 21:16

Make sure that you haven't renamed some folder which falls in the path of the M2 environment variable. In case you have, then change your M2 and/or M2_HOME accordingly.

It doesn't matter whether M2 or M2_HOME are System Variable or User Variables as long as you are logged in with the same user under whose scope the environment variables are.

查看更多
成全新的幸福
5楼-- · 2019-01-13 21:17

Just adding some more info that solved the problem for me:

  • Make sure that the %M2% and %M2_HOME% variables doesn't have the semicolon (;) at the end. This should only be used if there are more than one location in that path, which is not the case;
  • Also, make sure that in the "Path" variable, there aren't any spaces between the various paths, separated by the semicolon.

Thanks to Pawan Valecha and Abhijeet Sawant for the tips.

查看更多
迷人小祖宗
6楼-- · 2019-01-13 21:17

Maven should be configured in the following way (can be user variables or system): - M2: %M2_HOME%\bin - M2_HOME: (your directory to Maven's root, not \bin) - PATH: %PATH%;%M2%

You should then be able to run mvn from the command prompt.

查看更多
迷人小祖宗
7楼-- · 2019-01-13 21:17

I had the same issue, there was no issue in my syntax, but when I moved the M2, M2_HOME, JAVA_HOME environment variables from user to system it started working. Path variables stayed the same.

查看更多
登录 后发表回答