Java MAVEN_HOME、MVN_HOME 或 M2_HOME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26609922/
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-08-11 02:55:06  来源:igfitidea点击:

MAVEN_HOME, MVN_HOME or M2_HOME

javamavenmaven-2maven-3

提问by cassiomolin

What's the correct Maven environment variable name: MAVEN_HOME, MVN_HOMEor M2_HOME?

什么是正确的 Maven 环境变量名称:MAVEN_HOME,MVN_HOMEM2_HOME?

I've found some details about MAVEN_HOMEand M2_HOMEhere. But I also have seen MVN_HOMEaround.

我在MAVEN_HOMEM2_HOME这里找到了一些细节。但我也看到了MVN_HOME周围。

采纳答案by Steve C

I've personally never found it useful to set M2_HOME.

我个人从未发现设置M2_HOME.

What counts is your $PATH environment. HiHymaning part of the answer from Danix, all you need is:

重要的是您的 $PATH 环境。劫持 Danix 的部分答案,您只需要:

export PATH=/Users/xxx/sdk/apache-maven-3.0.5/bin:$PATH

The mvnscript computes M2_HOMEfor you anyway for what it's worth.

mvn脚本M2_HOME无论如何都会为您计算它的价值。

回答by Danix

Here is my Maven setup. You can use it as an example. You don't need anything else in order to use Maven.

这是我的 Maven 设置。您可以将其用作示例。您不需要任何其他东西即可使用 Maven。

M2_HOME is used for both Maven 2 and 3

M2_HOME 用于 Maven 2 和 3

export M2_HOME=/Users/xxx/sdk/apache-maven-3.0.5
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xmx1048m -Xms256m -XX:MaxPermSize=312M"
export PATH=$M2:$PATH

回答by imriss

$M2_HOMEis used sometimes, for example, to install Takari Extensions for Apache Maven

$M2_HOME有时用于,例如,安装 Takari Extensions for Apache Maven

One way to find $M2_HOMEvalue is to search for mvn:

找到$M2_HOME值的一种方法是搜索mvn

sudo find / -name "mvn" 2>/dev/null

And, probably it will be: /opt/maven/

而且,可能会是: /opt/maven/

回答by HariKishore

We have M2_HOME,MAVEN_HOME,M3_HOME all are available in market
Previously M2_HOME is the only environment variable used by all as a standard.
But,due latest releases the MAVEN_Home came as standard but some old tools are still trying to find only M2_HOME
so we should have both M2_HOME,MAVEN_HOME to sustain with old and new tools.
M2_HOME can be used for both as well

我们有M2_HOME,MAVEN_HOME,M3_HOME 都在市场
上可用以前M2_HOME 是唯一被所有人用作标准的环境变量。
但是,由于最新版本 MAVEN_Home 成为标准,但一些旧工具仍在尝试仅找到 M2_HOME,
因此我们应该同时拥有 M2_HOME、MAVEN_HOME 以支持新旧工具。
M2_HOME 也可用于两者

回答by UnclickableCharacter

M2_HOME(and the like) is not to be used as of Maven 3.5.0. See MNG-5607and Release Notesfor details.

M2_HOME(以及类似的)不从 Maven 3.5.0 开始使用。有关详细信息,请参阅MNG-5607发行说明

回答by prime

MAVEN_HOME is used for maven 1and M2_HOMEis used to locate maven 2. Having the two different _HOME variables means it is possible to run both on the same machine. And if you check old mvn.cmdscripts they have something like,

MAVEN_HOME 用于 maven 1M2_HOME用于定位 maven 2。拥有两个不同的 _HOME 变量意味着可以在同一台机器上运行两者。如果你检查旧的mvn.cmd脚本,它们会有类似的东西,

@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM     e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------

See that @REM M2_HOME - location of maven2's installed home dir

看到那个 @REM M2_HOME - location of maven2's installed home dir

Anyway usage of this pattern is now deprecated with maven 3.5 as per the documentation.

无论如何,根据文档,maven 3.5 现在不推荐使用此模式。

Based on problems in using M2_HOME related to different Maven versions installed and to simplify things, the usage of M2_HOME has been removed and is not supported any more MNG-5823, MNG-5836, MNG-5607

基于使用 M2_HOME 与安装的不同 Maven 版本相关的问题并为简化事情, M2_HOME 的用法已被删除,不再支持MNG-5823MNG-5836MNG-5607

So now the mvn.cmd look like,

所以现在 mvn.cmd 看起来像,

@REM -----------------------------------------------------------------------------
@REM Apache Maven Startup Script
@REM
@REM Environment Variable Prerequisites
@REM
@REM   JAVA_HOME          Must point at your Java Development Kit installation.
@REM   MAVEN_BATCH_ECHO  (Optional) Set to 'on' to enable the echoing of the batch commands.
@REM   MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
@REM   MAVEN_OPTS        (Optional) Java runtime options used when Maven is executed.
@REM   MAVEN_SKIP_RC     (Optional) Flag to disable loading of mavenrc files.
@REM -----------------------------------------------------------------------------

So what you need is JAVA_HOME to be set correctly. As per the new installation guide (as of 12/29/2017), Just add the maven bin directory path to the PATH variable. It should do the trick.

所以你需要的是正确设置 JAVA_HOME 。根据新的安装指南(截至 2017 年 12 月 29 日),只需将 maven bin 目录路径添加到 PATH 变量。它应该可以解决问题。

ex : export PATH=/opt/apache-maven-3.5.2/bin:$PATH

前任 : export PATH=/opt/apache-maven-3.5.2/bin:$PATH

回答by Miroslav Spasovski

I have solved same issue with following:

我已经用以下方法解决了同样的问题:

export M2_HOME=/usr/share/maven