MAVEN_HOME,MVN_HOME或M2_HOME

时间:2022-10-06 00:12:23

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

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

I've found some details about MAVEN_HOME and M2_HOME here. But I also have seen MVN_HOME around.

我在这里找到了关于MAVEN_HOME和M2_HOME的一些细节。但我也见过MVN_HOME。

6 个解决方案

#1


30  

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

我个人从未发现设置M2_HOME很有用。

What counts is your $PATH environment. Hijacking 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 mvn script computes M2_HOME for you anyway for what it's worth.

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

#2


16  

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

#3


2  

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

例如,有时会使用$ M2_HOME为Apache Maven安装Takari Extensions

One way to find $M2_HOME value is to search for mvn:

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

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

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

并且,可能是:/ opt / maven /

#4


2  

M2_HOME (or any other) is not to be used as of Maven 3.5.0. See MNG-5607 and Release Notes for details.

从Maven 3.5.0起不使用M2_HOME(或任何其他)。有关详细信息,请参阅MNG-5607和发行说明。

#5


2  

MAVEN_HOME is used for maven 1 and M2_HOME is 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.cmd scripts they have something like,

MAVEN_HOME用于maven 1,M2_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 - maven2的已安装主目录的位置

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

基于使用与安装的不同Maven版本相关的M2_HOME的问题并简化操作,M2_HOME的使用已被删除,不再支持MNG-5823,MNG-5836,MNG-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。根据新安装指南(截至12/29/2017),只需将maven bin目录路径添加到PATH变量即可。它应该做的伎俩。

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

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

#6


-3  

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也可用于两者

#1


30  

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

我个人从未发现设置M2_HOME很有用。

What counts is your $PATH environment. Hijacking 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 mvn script computes M2_HOME for you anyway for what it's worth.

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

#2


16  

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

#3


2  

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

例如,有时会使用$ M2_HOME为Apache Maven安装Takari Extensions

One way to find $M2_HOME value is to search for mvn:

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

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

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

并且,可能是:/ opt / maven /

#4


2  

M2_HOME (or any other) is not to be used as of Maven 3.5.0. See MNG-5607 and Release Notes for details.

从Maven 3.5.0起不使用M2_HOME(或任何其他)。有关详细信息,请参阅MNG-5607和发行说明。

#5


2  

MAVEN_HOME is used for maven 1 and M2_HOME is 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.cmd scripts they have something like,

MAVEN_HOME用于maven 1,M2_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 - maven2的已安装主目录的位置

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

基于使用与安装的不同Maven版本相关的M2_HOME的问题并简化操作,M2_HOME的使用已被删除,不再支持MNG-5823,MNG-5836,MNG-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。根据新安装指南(截至12/29/2017),只需将maven bin目录路径添加到PATH变量即可。它应该做的伎俩。

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

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

#6


-3  

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也可用于两者