windows 如何将 Maven 添加到 Path 变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45119595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:54:47  来源:igfitidea点击:

How to add Maven to the Path variable?

windowsmavenpath

提问by Salman Lashkarara

I have downloaded the maven 3.5.0from here. I have set it in the path:

我已经从这里下载了Maven 3.5.0。我已将其设置在路径中:

C:\apache-maven-3.5.0

Then i treid to add it to the path of Windows 7as below:

然后我尝试将其添加到如下路径Windows 7中:

  1. Right click on my computer

  2. Properties

  3. Advanced System Setting

  4. Environment Variable

  5. New user variable and added Maven_Homewith value C:\apache-maven-3.5.0

  6. Add it to path variable with: %Maven_Home%\bin

  7. Open cmdand ask for mvn -versionin desktop

  1. 右键单击我的电脑

  2. 特性

  3. 高级系统设置

  4. 环境变量

  5. 新的用户变量并添加Maven_Home了值C:\apache-maven-3.5.0

  6. 使用以下命令将其添加到路径变量: %Maven_Home%\bin

  7. 桌面打开cmd并请求mvn -version

Result:

结果

It does not recognize maven

它无法识别 maven

采纳答案by Salman Lashkarara

The problem get solved when i edit the pathvariable with ;%Maven_Home%\bin;so i should add the ;before and after it.

当我编辑path变量时问题得到解决,;%Maven_Home%\bin;所以我应该;在它之前和之后添加它。

回答by Krishna

In windows:

在窗口中:

Download the latest version of Maven from the http://maven.apache.org/and Navigate to Use --> Download --> Download the Binary zip archive.

http://maven.apache.org/下载最新版本的 Maven,然后导航到使用 --> 下载 --> 下载二进制 zip 存档。

1)After the download, unzip the folder and copy it to the folder. (Lets say i have copied to c:\program files\apache-maven-3.52.

1)下载后,解压文件夹,复制到文件夹中。(假设我已复制到 c:\program files\apache-maven-3.52。

2)Setting the path of Maven in environment Variables:Search the Environment Variable --> Edit the System Environment variables--> Navigate to Advanced tab --> Environment Variables

2)在环境变量中设置Maven的路径:搜索环境变量-->编辑系统环境变量-->导航到高级选项卡-->环境变量

i) MAVEN_HOME :Click New --> Variable Name : MAVEN_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2

i) MAVEN_HOME :点击新建 --> 变量名:MAVEN_HOME,变量值:C:\Program Files\apache-maven-3.5.2

ii) M2_HOME :Click New --> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2

ii) M2_HOME:点击新建 --> 变量名称:M2_HOME,变量值:C:\Program Files\apache-maven-3.5.2

iii) Edit the 'Path'Environment Variable --> %M2_HOME%\bin

iii) 编辑 'Path'环境变量 --> %M2_HOME%\bin

Testing whether Maven is installed:mvn -version

测试是否安装了Maven:mvn -version

References:-http://www.baeldung.com/install-maven-on-windows-linux-mac

参考资料:-http://www.baeldung.com/install-maven-on-windows-linux-mac

NOTE : In point iii don't forget to put semicolon(;) before and after.

注意:在第 iii 点不要忘记在前后加上分号(;)。

回答by user13054935

  1. Open command console
  2. copy this set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
  3. cahnge the path accordingly
  4. click enter
  1. 打开命令控制台
  2. 复制这个 设置 PATH="c:\program files\apache-maven-3.xy\bin";%PATH%
  3. 相应地改变路径
  4. 点击进入

it's all set and now check mvn -version

一切就绪,现在检查 mvn -version

回答by Diorcula

I had the same problem and fixed the issue by:

我遇到了同样的问题,并通过以下方式解决了这个问题:

  • Adding the M2_HOME to the USER VARIABLES
  • Adding the MAVEN_HOME to the USER VARIABLES

  • Adding the BIN folder to the PATH in the SYSTEM VARIABLES

  • 将 M2_HOME 添加到用户变量
  • 将 MAVEN_HOME 添加到 USER VARIABLES

  • 将 BIN 文件夹添加到 SYSTEM VARIABLES 中的 PATH

(conform this video: https://www.youtube.com/watch?v=RfCWg5ay5B0)

(符合此视频:https: //www.youtube.com/watch?v=RfCWg5ay5B0

Then i could run mvn -versionin a NEW command terminal.

然后我可以mvn -version在新的命令终端中运行。

回答by Prp

Adding

添加

  1. MAVEN_HOMEvariable (C:\Program Files\apache-maven-3.5.2) and M2_HOMEvariable (C:\Program Files\apache-maven-3.5.2\bin).
  2. Add %MAVEN_HOME%\binto the path in system variables . Then mvn -version in command prompt.
  1. MAVEN_HOME变量 (C:\Program Files\apache-maven-3.5.2) 和M2_HOME变量 (C:\Program Files\apache-maven-3.5.2\bin)。
  2. 添加%MAVEN_HOME%\bin到系统变量中的路径。然后在命令提示符下 mvn -version 。

回答by Anshul Sharma

1) Make sure JDK is installed, and “JAVA_HOME” variable is added as Windows environment variable.

1) 确保安装了 JDK,并添加了“JAVA_HOME”变量作为 Windows 环境变量。

1) Download the Maven zip file, for example : apache-maven-3.5.0-bin.zip. Unzip it to the folder you want to install Maven. Assume you unzip to this folder – C:\Program Files\Apache\maven

1) 下载Maven zip 文件,例如:apache-maven-3.5.0-bin.zip。解压到你要安装Maven的文件夹。假设你解压到这个文件夹——C:\Program Files\Apache\maven

3) Set the environment variables using system properties. Add M2_HOME, M2, MAVEN_OPTS to environment variables.

3) 使用系统属性设置环境变量。将 M2_HOME、M2、MAVEN_OPTS 添加到环境变量中。

M2_HOME=C:\Program Files\Apache\maven\apache-maven-3.5.0

M2=%M2_HOME%\bin

MAVEN_OPTS=-Xms256m -Xmx512m

4) Now append M2 variable to System Path. Append the string ;%M2%to the end of the system variable, Path.

4) 现在将 M2 变量附加到系统路径。将字符串附加;%M2%到系统变量 Path 的末尾。

5) Open Command Console and run this command c:\> mvn --version

5)打开命令控制台并运行此命令 c:\> mvn --version

you will get bellow output :

你会得到以下输出:

Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3

Java version: 1.7.0_75, vendor: Oracle Corporation

Java home: C:\Program Files\Java\jdk1.7.0_75\jre

Default locale: en_US, platform encoding: Cp1252