简体   繁体   English

Maven:未找到 mvn 命令

[英]Maven: mvn command not found

I set the following system veriables (OS = Vista):我设置了以下系统验证(OS = Vista):

M2_HOME = C:\Program Files\Maven 
M2 = %M2_HOME%\bin 
path = %M2% 

If i run mvn -- version I get:如果我运行 mvn -- 版本我得到:

mvn: command not found

Anyone have any idea why this could be?任何人都知道为什么会这样? Thanks.谢谢。

If you are on windows, what i suppose you need to do set the PATH like this:如果您在 Windows 上,我想您需要像这样设置 PATH:

SET PATH=%M2%

furthermore i assume you need to set your path to something like C:...\\apache-maven-3.0.3\\ cause this is the default folder for the windows archive.此外,我假设您需要将路径设置为 C:...\\apache-maven-3.0.3\\ 之类的内容,因为这是 Windows 存档的默认文件夹。 On the other i assume you need to add the path of maven to your and not set it to only maven so you setting should look like this:另一方面,我假设您需要将 maven 的路径添加到您的而不是将其设置为仅 maven,因此您的设置应如下所示:

SET PATH=%PATH%;%M2%

I tried solutions from other threads.我尝试了其他线程的解决方案。 Adding M2 and M2_HOME at System variables, and even at User variables.在系统变量甚至用户变量中添加 M2 和 M2_HOME。 Running cmd as admin.以管理员身份运行 cmd。 None of the methods worked.没有一种方法奏效。

But today I added entire path to maven bin to my System variables "PATH" (C:\\Program Files (x86)\\Apache Software Foundation\\apache-maven-3.1.0\\bin) besides other paths, and so far it's working good.但是今天我将 maven bin 的整个路径添加到我的系统变量“PATH”(C:\\Program Files (x86)\\Apache Software Foundation\\apache-maven-3.1.0\\bin)除了其他路径之外,到目前为止它运行良好. Hopefully it'll stay that way.希望它会一直这样。

I followed this tutorial: How to install Maven on Windows我遵循了本教程: 如何在 Windows 上安装 Maven

But running mvn -version , I still got:但是运行mvn -version ,我仍然得到:

mvn: command not found mvn:找不到命令

So, I closed the current git window, and opened a new one.所以,我关闭了当前的 git 窗口,并打开了一个新窗口。 Everything went okay :)一切顺利:)

Maven setup: Maven设置:

a.一种。 install maven from https://maven.apache.org/download.cgihttps://maven.apache.org/download.cgi安装 maven

b.unzip maven and keep in C drive.解压maven并保存在C盘。

c. C。 Set MAVEN_HOME in system variable.在系统变量中设置MAVEN_HOME 在此处输入图片说明

d. d. Set path for maven为maven设置路径在此处输入图片说明

  1. Run ' path ' in command prompt and ensure that the maven installation directory is listed.在命令提示符下运行“ path ”并确保列出了 maven 安装目录。
  2. Ensure the maven is installed in 'C:\\Program Files\\Maven'.确保 maven 安装在“C:\\Program Files\\Maven”中。

I think the problem is with the spaces.我认为问题出在空格上。 I had my variable at the System variables but it didn't work.我在系统变量中有我的变量,但它不起作用。 When I changed variable Progra~1 = 'Program Files' everything works fine.当我更改变量Progra~1 = 'Program Files'一切正常。

M2_HOME C:\Progra~1\Maven\apache-maven-3.1.1

I also moved my M2_HOME at the end of the PATH(%M2_HOME%\\bin) I'm not sure if this has any difference.我还在PATH(%M2_HOME%\\bin)的末尾移动了我的M2_HOME我不确定这是否有任何区别。

mvn -version mvn -version

export PATH=$PATH:/opt/apache-maven-3.6.0/bin导出 PATH=$PATH:/opt/apache-maven-3.6.0/bin

I think the tutorial passed by @emdhie will help a lot.我认为@emdhie 通过的教程会有很大帮助。 How install maven 怎么安装maven

But, i followed and still getting mvn: command not found但是,我跟着,仍然得到mvn: command not found

I found this solution to know what was wrong in my configuration:我找到了这个解决方案来了解我的配置出了什么问题:

I opened the command line and called this command:我打开命令行并调用了这个命令:

../apache-maven-3.5.3/bin/mvn --version

After that i got the correct JAVA_HOME and saw that my JAVA_HOME was wrong.之后我得到了正确的 JAVA_HOME 并看到我的 JAVA_HOME 是错误的。

Hope this helps.希望这可以帮助。

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

相关问题 exec-maven-plugin无法在Windows计算机上运行“ mvn”命令 - exec-maven-plugin cannot run “mvn” command on Windows machine 无法在 Microsoft Powershell 中使用“mvn -D”参数运行 Maven,但可以在命令提示符下运行 - Cannot run Maven using `mvn -D` argument within Microsoft Powershell, but works in Command Prompt mvn'不被识别为内部或外部命令 - mvn' is not recognized as an internal or external command cmd找不到mvn命令 - cmd cannot find mvn command Jenkins Windows从属节点上无法识别'mvn'命令 - 'mvn' command not recognized on Jenkins Windows slave node mvn - 在 Windows 11 中不被识别为内部或外部命令 - mvn - is not recognized as an internal or external command in Windows 11 mvn maven-thucydides-plugin JAR访问被拒绝 - mvn maven-thucydides-plugin JAR access denied mvn archtype:generate命令不适用于Windows中的D:或d: - mvn archtype:generate command does not work on D: or d: in windows C:WINDOWSsystem32configsystemprofileAppDataLocalJenkins.jenkinstoolshudson.tasks.Maven_MavenInstallationmaven/bin/mvn: 没有那个文件或目录 - C:WINDOWSsystem32configsystemprofileAppDataLocalJenkins.jenkinstoolshudson.tasks.Maven_MavenInstallationmaven/bin/mvn: No such file or directory 找不到Samba testparam命令 - Samba testparam command not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM