简体   繁体   English

'mvn' 不是内部或外部命令,也不是可运行的程序或批处理文件

[英]'mvn' is not recognized as an internal or external command, operable program or batch file

May be question is asked before but i found very strange kind of error.可能之前有人问过问题,但我发现了一种非常奇怪的错误。 When I run mvn --version command from bin its gives the version and the other information.当我从 bin 运行mvn --version命令时,它会提供版本和其他信息。 However when I run outside bin it gives exception.但是,当我在 bin 外运行时,它会出现异常。 Both the result mention below两个结果都在下面提到

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin>mvn --version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:
28+0530)
Maven home: C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5>mvn --version
'mvn' is not recognized as an internal or external command,
operable program or batch file.

Also i set JAVA_HOME in user variable and M2_HOME, M2 in system environment variable output is另外我在用户变量和 M2_HOME 中设置了 JAVA_HOME,系统环境变量输出中的 M2 是

C:\Users\SAHILBHALLA>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_25

C:\Users\SAHILBHALLA>echo %M2%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin

C:\Users\SAHILBHALLA>echo %M2_HOME%
C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5

Tell me where i am wrong.告诉我哪里错了。 What should i do recover from it?我该怎么做才能从中恢复?

My problem solved, path didn't resolve %M2% .我的问题解决了, path没有解决%M2% When i added location of maven-bin in the path instead of %M2% after that commands works.当我在路径中添加了 maven-bin 的位置而不是%M2%在该命令起作用后。

I would like to thanks to all those who try to solve the problem我要感谢所有试图解决问题的人

maven should be on the system's PATH if you wish to execute it from any place.如果你想从任何地方执行 maven,它应该在系统的 PATH 上。 add %M2_HOME%\\bin to the PATH将 %M2_HOME%\\bin 添加到 PATH

First of all make sure you java is working or not run this command in cmd首先确保您的java正在工作或不在cmd中运行此命令

 C:\>java -version

if it's working it will show this output:-如果它正在工作,它将显示此输出:-

C:\>java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)

step 1. First set your java_home[C:\\Program Files\\Java\\jdk1.8.0_74] path in user variable.步骤 1.首先在用户变量中设置您的 java_home[C:\\Program Files\\Java\\jdk1.8.0_74] 路径。

step 2. Then set MAVEN_HOME[C:\\Program Files\\maven\\apache-maven-3.3.9] path in system variable and make sure your maven folder should be present in C folder only.步骤 2.然后在系统变量中设置 MAVEN_HOME[C:\\Program Files\\maven\\apache-maven-3.3.9] 路径,并确保您的 maven 文件夹应该只出现在 C 文件夹中。

step 3. Then set M2 path in system variable and give maven bin location there ie[C:\\Program Files\\maven\\apache-maven-3.3.9\\bin].步骤 3.然后在系统变量中设置 M2 路径并在那里给出 maven bin 位置,即 [C:\\Program Files\\maven\\apache-maven-3.3.9\\bin]。

Step 4. Then set new system variable ie variable name = MAVEN_OPTS in and variable value =-Xms256m -Xmx512m步骤 4.然后设置新的系统变量,即变量名= MAVEN_OPTS 和变量值=-Xms256m -Xmx512m

Step 5. Then edit path/system path variable be care full don't remove anything from there simply add java_home path ie=;C:\\Program Files\\Java\\jdk1.8.0_74 and M2 variable=;%M2% in the end.步骤 5.然后编辑路径/系统路径变量,小心不要从那里删除任何东西,只需添加 java_home 路径 ie=;C:\\Program Files\\Java\\jdk1.8.0_74 和 M2 variable=;%M2% 最后.

Step 6. To make sure maven is now working or not run this command in cmd步骤 6.确保 maven 现在正在工作或不在 cmd 中运行此命令

> C:\>mvn --version

if it's working it will show this result :-如果它正在工作,它将显示此结果:-

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-
7+05:30)
Maven home: C:\Program Files\maven\apache-maven-3.3.9\bin\..
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_74\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "dos"

In Windows 10, I had to run the windows command prompt (cmd) as administrator.在 Windows 10 中,我必须以管理员身份运行 Windows 命令提示符 (cmd)。 Doing that solved this problem for me.这样做为我解决了这个问题。

This problem arise because there is no any environmental variable corresponding to installed maven in your OS.出现此问题是因为您的操作系统中没有与安装的 maven 相对应的任何环境变量。 For fixing this problem, I always use Intellij's bundled Maven and do not install separate version of Maven again, for finding bundled Maven's path go to intellij and hit Ctrl+Alt+S -> Build, Execution, Deployment -> Build tool -> Maven -> Maven home directory you can find the intellij's bundled maven path there as below image demonstrates.为了解决这个问题,我总是使用 Intellij 的捆绑 Maven 并且不再安装单独版本的 Maven,要找到捆绑 Maven 的路径,请转到 Intellij 并点击Ctrl+Alt+S -> Build, Execution, Deployment -> Build tool -> Maven -> Maven home directory您可以在那里找到 Intellij 的捆绑 Maven 路径,如下图所示。

在此处输入图片说明

Then go to System environment variables and set these variables:然后转到System environment variables并设置这些变量:

Variable name: MAVEN_HOME变量名:MAVEN_HOME

Variable value: C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1/plugins/maven/lib/maven3变量值:C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1/plugins/maven/lib/maven3

在此处输入图片说明

After defining system variable MAVEN_HOME find variable path and add this line to the list定义系统变量MAVEN_HOME找到变量path并将此行添加到列表中

%MAVEN_HOME%\\bin

在此处输入图片说明

Work is done, open command prompt and test it by writing mvn -v .工作完成,打开命令提示符并通过编写mvn -v测试它。 99 percent of the time it work, if you're among 1 percent, you have to restart your computer. 99% 的时间它都在工作,如果你是其中的 1%,你必须重新启动你的计算机。

If you want to use mvn command from intellij's internal terminal you have to restart intellij after setting environment variables, then you shouldn't have any problem running maven command from terminal.如果你想从 intellij 的内部终端使用mvn命令,你必须在设置环境变量后重新启动 intellij,那么从终端运行 maven 命令应该没有任何问题。

In windows 7, I Got it resolved after adding the environment variables in system level.在 Windows 7 中,我在系统级别添加环境变量后解决了这个问题。 If you do not have enough permission try to set the %JAVA_HOME% and the %M2_HOME% in System variables instead of User Variables.如果您没有足够的权限,请尝试在系统变量而不是用户变量中设置%JAVA_HOME%%M2_HOME%

mvn的完整路径放在PATH环境变量中。

After setting the path with the Maven bin location close the prompt window and restart it.使用Maven bin位置设置路径后关闭提示窗口并重新启动它。 Use the echo %path% command to make sure the path is set with Maven variables then run the command mvn -version .使用echo %path%命令确保使用 Maven 变量设置路径,然后运行命令mvn -version Somehow if the path is set when the prompt window is running it does not pick the new variables.不知何故,如果在提示窗口运行时设置了路径,它不会选择新变量。

To solve this problem please follow the steps below:要解决此问题,请按照以下步骤操作:

  1. Download the maven zip file from http://maven.apache.org/download.cgihttp://maven.apache.org/download.cgi下载 maven zip 文件
  2. Extract the maven zip file解压 Maven zip 文件
  3. Open the environment variable and in user variable section click on new button and make a variable called MAVEN_HOME and assign it the value of bin path of extracted maven zip打开环境变量并在用户变量部分单击按钮并创建一个名为MAVEN_HOME的变量并将其分配为提取的 maven zip 的 bin 路径值
  4. Now in System Variable click on Path and click on Edit button --> Now Click on New button and paste the bin path of maven zip现在在系统变量中单击路径并单击编辑按钮-> 现在单击新建按钮并粘贴 maven zip 的bin路径
  5. Now click on OK button现在点击确定按钮
  6. Open CMD and type mvn -version打开CMD并输入mvn -version
  7. Installed Maven version will be displayed and your setup is completed将显示已安装的 Maven 版本并且您的设置已完成

Here is the best Maven-Environment Setup tutorial for Windows, Unix and Mac Operating systems. 是适用于 Windows、Unix 和 Mac 操作系统的最佳 Maven 环境设置教程。

But in the last you have to set value of PATH variable as ";%M2_HOME%\\bin" instead of "%M2%" , because PATH variable is not able to reduce the value using "%M2%"但最后你必须将PATH变量的值设置为";%M2_HOME%\\bin"而不是"%M2%" ,因为PATH变量不能使用 "%M2%" 来减少值

got it solved by first creating new "Path" variable under User variables (note that after fresh windows install Path variable is not created as User variable, only as system) after that, I appended %M2% (pointing to maven dir/bin) to (freshly created) user Path variable.通过首先在用户变量下创建新的“路径”变量来解决它(请注意,在新的 Windows 安装后,路径变量不是作为用户变量创建的,而是作为系统创建的)之后,我附加了 %M2%(指向 maven dir/bin)到(新创建的)用户路径变量。 after that restarted cmd window and it worked like a charm.之后重新启动 cmd 窗口,它就像一个魅力。

Go to the shell (cmd for windows) and set the path variable manually from there.转到外壳程序(Windows 的 cmd)并从那里手动设置路径变量。 It works often from there.它经常从那里工作。 Read more at http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/阅读更多信息

Go to Environment Variable and paste the following:转到环境变量并粘贴以下内容:

Under System Variable: Step 1: New --> New User Variable 1. Variable name: MAVEN_HOME 2. Variable_value : D:\\apache-maven-3.5.2在系统变量下: Step 1: New --> New User Variable 1. 变量名:MAVEN_HOME 2. Variable_value : D:\\apache-maven-3.5.2

Step 2: 1. Go to the path --> and paste this - %MAVEN_HOME%\\bin第 2 步: 1. 转到路径 --> 并粘贴此 - %MAVEN_HOME%\\bin

The following helped me in Win10.以下在Win10中帮助了我。

  • Add %M3_HOME%\\bin;添加%M3_HOME%\\bin; as value for Path variable under User Variables.作为用户变量下路径变量的值。
  • Add full path to maven binary folder as Variable Value for M3_HOME variable under System Variables.将 maven 二进制文件夹的完整路径添加为M3_HOME变量下M3_HOME变量的变量值。
  • Add %M3_HOME%\\bin;添加%M3_HOME%\\bin; as value for Path variable under System Variables.作为系统变量下路径变量的值。
  • Click OK wherever applicable.在适用的地方单击“确定”。
  • Close the existing command prompt.关闭现有的命令提示符。
  • Open new command prompt and navigate to Maven binary folder.打开新的命令提示符并导航到 Maven 二进制文件夹。
  • Type mvn -version输入mvn -version

It will work.它会起作用。

I prefer adding path to ~/.bashrc.我更喜欢将路径添加到 ~/.bashrc。

vim ~/.bashrc, then add these lines: vim ~/.bashrc,然后添加以下几行:

export M2_HOME=/usr/local/apache-maven-your_maven_path&version
export M2=$M2_HOME/bin

I did all of this in Windows 10 and still had a problem.我在 Windows 10 中做了所有这些,但仍然有问题。 In the end it turned out that the path to the Maven home folder was not exactly what was expected in many of these answers as it turned out to be /apache-maven-3.6.3-bin/apache-maven-3.6.3.最后发现 Maven 主文件夹的路径并不完全符合这些答案中的预期,因为它是 /apache-maven-3.6.3-bin/apache-maven-3.6.3。 Once I corrected this for both the system variables and the PATH variable, it worked.一旦我为系统变量和 PATH 变量纠正了这个问题,它就起作用了。 In short, if you have set the environment variables up as directed and it still won't work, I would double check to make sure the variables really point to the exact path to the Maven home folder and the bin folder on your machine.简而言之,如果您按照指示设置了环境变量,但它仍然不起作用,我会仔细检查以确保变量确实指向 Maven 主文件夹和机器上 bin 文件夹的确切路径。

Try these steps...试试这些步骤...

cmd : mvn -version cmd : mvn -version

go apache-maven folder > bin去 apache-maven 文件夹> bin

copy the path and go System properties > environment variables > system variables复制路径并转到系统属性>环境变量>系统变量

path > edit > [paste the file path]路径 > 编辑 > [粘贴文件路径]

next restart your machine.接下来重启你的机器。

https://youtu.be/RQ_Z859Hd7Q https://youtu.be/RQ_Z859Hd7Q

暂无
暂无

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

相关问题 无法将“ mvn”识别为内部或外部命令,可操作程序或批处理文件(Win10) - 'mvn' is not recognized as an internal or external command, operable program or batch file (Win10) 解决问题的分步方法是什么:'mvn'不被识别为内部或外部命令,可操作程序或批处理文件 - What is the step-by-step approach to solving: 'mvn' is not recognized as an internal or external command, operable program or batch file 错误 -'javac' 不是内部或外部命令,也不是可运行的程序或批处理文件 - Error -'javac' is not recognized as an internal or external command, operable program or batch file 'cmd'未被识别为内部或外部命令,可操作程序或批处理文件 - 'cmd' is not recognized as an internal or external command, operable program or batch file VSCode 'java' 不是内部或外部命令,也不是可运行的程序或批处理文件 - VSCode 'java' is not recognized as an internal or external command, operable program or batch file 错误 - jar 不是内部或外部命令、可运行的程序或批处理文件 - Error - jar is not recognized as an internal or external command, operable program or batch file 'jar' 不是内部或外部命令、可运行程序或批处理文件错误 - 'jar' is not recognized as an internal or external command, operable program or batch file error 'appletviewer' 不是内部或外部命令,也不是可运行的程序或批处理文件 - 'appletviewer' is not recognized as an internal or external command, operable program or batch file 'wsgen'不被识别为内部或外部命令,可操作程序或批处理文件 - 'wsgen' is not recognized as an internal or external command, operable program or batch file 'scomp' 不是内部或外部命令,也不是可运行的程序或批处理文件 - 'scomp' is not recognized as an internal or external command, operable program or batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM