简体   繁体   English

mvn'不被识别为内部或外部命令

[英]mvn' is not recognized as an internal or external command

I have created these variables with their respective values, but even after doing this, command prompt is not recognizing mvn command 我已经用它们各自的值创建了这些变量,但是即使这样做,命令提示符仍无法识别mvn命令
System Variables: 系统变量:

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

  • name: M2 名称: M2
  • value: %M2_HOME%/bin; 值: %M2_HOME%/bin;

  • name: path 名称: path
  • value: %JAVA_HOME%\\bin; %M2_HOME%\\bin; 值: %JAVA_HOME%\\bin; %M2_HOME%\\bin; %JAVA_HOME%\\bin; %M2_HOME%\\bin;

From Maven documentation page : Maven文档页面

Maven, like many cross-platform tools, can encounter problems when there are space characters in important pathnames . 与许多跨平台工具一样,当重要路径名中包含空格字符时,Maven可能会遇到问题。 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 您已经在C:\\Program Files\\apache-maven-3.2.1安装了Maven

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 尝试将其重新安装到例如C:\\maven ,或将当前变量M2_HOME更改为C:\\PROGRA~1\\apache-maven-3.2.1

try : 尝试:

  • to restart the command prompt 重新启动命令提示符
  • to start the command prompt with run/cmd instead of shift+right-click -" open command window here " 使用run / cmd而不是shift +右键单击来启动命令提示符-“ 在此处打开命令窗口
  • to put the system path between double quote to manage espace character 将系统路径放在双引号之间以管理espace字符
  • to replace C:\\Program Files\\ per C:\\PROGRA~1\\ 每个C:\\PROGRA~1\\ C:\\Program Files\\替换C:\\Program Files\\ 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

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" 只需删除空格字符,我就能使一切正常工作”

this is the settings for my maven. 这是我的专家的设置。

name: MVN_HOME value: C:\\Program Files\\apache-maven-3.2.1 名称:MVN_HOME值: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; 名称:path->添加以下值(仅是Maven部分):%JAVA_HOME%\\ bin;%MVN_HOME%\\ bin; -> this should have no spaces ->这个应该没有空格

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. 无论我如何在Win7的控制面板中设置环境变量,它都不起作用。

My final solution is to set the variables via the cmd. 我的最终解决方案是通过cmd设置变量。

set M2_HOME "D:\Program Files\Maven\apache-maven-3.3.3"
set M2=%M2_HOME%\bin
set path=%path%;%M2%

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. 如果不起作用,请更改路径%M2_HOME%\\ bin。 in this case: 在这种情况下:

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

确保在系统变量而不是用户变量下设置路径。

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". 就我而言,由于无法解释的原因,如果在“系统变量”与“用户变量”中定义了MAVEN_HOME环境变量,则对Windows 7有所不同。

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;") 我最初同时具有JAVA_HOME和MAVEN_HOME作为“用户变量”和“ Java -version”,但是Windows找不到mvn(在两种情况下,我的路径变量都看起来像这样:“ 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. 一旦将两个环境变量从“用户变量”更改为“系统变量”,Windows便可以找到mvn。

I had the same issue. 我遇到过同样的问题。

What I did to resolve this is creating M2_HOME & MAVEN_HOME. 解决此问题的方法是创建M2_HOME和MAVEN_HOME。 Also, edit Path variable value. 另外,编辑路径变量值。

创建了两个系统变量M2_HOME和MAVEN_HOME

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

New -> C:\\Program Files\\Apache Software Foundation\\apache-maven-3.6.0\\bin 新建-> 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. 我在其中创建了Apache Software Foundation文件夹,以提取apache-maven-3.6.0-bin.zip文件。

Also, make sure Java is working fine and JAVA_HOME is properly set. 另外,请确保Java正常运行并且正确设置了JAVA_HOME。

在此处输入图片说明

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. 我在变量path使用了%MAVEN_HOME% ,即使echo %MAVEN_HOME%命令显示了正确的路径,也给我带来了问题。

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. 我将其更改为路径中的C:\\Program Files\\apache-maven-3.6.1\\bin (取决于您的课程版本),它的工作原理很吸引人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM