JAVA_HOME、M2 和 M2_HOME 变量的用途

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

Purpose of the JAVA_HOME, M2, and M2_HOME variables

javamavenpath

提问by Liza Tjaica

What do I need the JAVA_HOME, M2, and M2_HOMEenvironment variables for if the paths that should go there are already appended to my PATH variable?

我需要做什么的JAVA_HOMEM2以及M2_HOME环境变量是否应该走的道路目前已经追加到我的PATH变量?

回答by AlexR

JAVA_HOMEshould refer to directory where Java that you want to use is installed. This variable is often used by various scripts, so it is recommended to define it. JAVA_HOMEitself should not be added to PATH. You should add JAVA_HOME/binto be able to run commands from this directory without specifying the concrete path.

JAVA_HOME应该是指您要使用的 Java 的安装目录。这个变量经常被各种脚本使用,所以建议定义它。JAVA_HOME本身不应添加到PATH. 您应该添加JAVA_HOME/bin以便能够在不指定具体路径的情况下从该目录运行命令。

M2_HOMEis a home of Maven. It is used by script mvn(or mvn.baton Windows).

M2_HOME是Maven的家。它由脚本mvn(或mvn.bat在 Windows 上)使用。

回答by prashantsunkari

The home paths (JAVA_HOME, M2_HOME) are not mandatory but good to have. One of the advantages is:

主路径 ( JAVA_HOME, M2_HOME) 不是强制性的,但很好。优点之一是:

It helps you make changes at one place rather than search you way in the PATHvariable when you install next version of Java or Maven. For example JAVA_HOMEenvironment variable below is a one place I need to change when I upgrade it to Java Development Kit 1.8.

PATH当您安装下一版本的 Java 或 Maven 时,它可以帮助您在一个地方进行更改,而不是在变量中搜索您的方式。例如,JAVA_HOME下面的环境变量是我升级到 Java Development Kit 1.8 时需要更改的一个地方。

Windows environment variable window

Windows 环境变量窗口

回答by Alexander Pogrebnyak

I think you do not understand a concept of environment variable. For start, read here -> http://en.wikipedia.org/wiki/Environment_variable

我认为您不了解环境变量的概念。首先,请阅读此处 -> http://en.wikipedia.org/wiki/Environment_variable

PATHis one environment variable that is well known in many operating systems (or shells). And it's meaning is that if you type a program name without full path, operating system (or shell) will try to search all directories specified in PATHvariable.

PATH是许多操作系统(或外壳程序)中众所周知的一种环境变量。这意味着如果您键入没有完整路径的程序名称,操作系统(或外壳程序)将尝试搜索PATH变量中指定的所有目录。

Other programs have different dependencies on the environment. Some of them specify which environment variables they need in order to run properly.

其他程序对环境有不同的依赖性。其中一些指定了他们需要哪些环境变量才能正常运行。

JAVA_HOMEis used by many Java-based applications to define the place of Java Runtime Environment (JRE) installation.

JAVA_HOME许多基于 Java 的应用程序使用它来定义 Java 运行时环境 (JRE) 的安装位置。

M2_HOMEis used by Maven, and again it tells the program where to find Maven installation.

M2_HOME由 Maven 使用,它再次告诉程序在哪里可以找到 Maven 安装。

PATHis not suitable for that purpose, because it may contain many directories not related to Java or Maven.

PATH不适合该目的,因为它可能包含许多与 Java 或 Maven 无关的目录。

回答by PatS

The PATH variable is used to find applications (executables, and scripts) and DLLs on Windows. If you type "mvn", then the PATH is used to locate an executable or script of that name. Just because the script is found in a location, however, doesn't mean that the application is installed in that directory. The easiest example to describe is one that exists on UNIX. You might have a symbolic link from /usr/local/bin/mvn to the location where maven is actually installed. Other examples/reasons could be given.

PATH 变量用于在 Windows 上查找应用程序(可执行文件和脚本)和 DLL。如果您键入“mvn”,则 PATH 用于定位该名称的可执行文件或脚本。然而,仅仅因为脚本位于某个位置,并不意味着应用程序安装在该目录中。描述最简单的示例是存在于 UNIX 上的示例。您可能有一个从 /usr/local/bin/mvn 到 maven 实际安装位​​置的符号链接。可以给出其他示例/原因。

The environment variables are used by the application to know where to look for other resources the application might need.

应用程序使用环境变量来了解在何处查找应用程序可能需要的其他资源。

For example, JAVA_HOME points to the directory where your JDK can be found. When JAVA runs, that application knows that other resources can be found relative to the JAVA_HOME directory.

例如,JAVA_HOME 指向可以找到您的 JDK 的目录。当 JAVA 运行时,该应用程序知道可以找到相对于 JAVA_HOME 目录的其他资源。

This allows the application for example C:\Windows\System32\java to exist in one directory but the JDK installation to be located somewhere else.

这允许应用程序例如 C:\Windows\System32\java 存在于一个目录中,而 JDK 安装位于其他地方。

The same applies for the M2_HOME directory which points to the top directory where MAVEN is "installed" (or unzipped).

这同样适用于 M2_HOME 目录,它指向“安装”(或解压缩)MAVEN 的顶级目录。

The M2 directory specifies to the maven application (mvn) where to find the maven repositories that are needed. The default (on UNIX) is $HOME/.m2, but you might not want your repository there so you can specify another location using the M2 environment variable and maven will use that location instead of the default.

M2 目录指定 maven 应用程序 (mvn) 在哪里可以找到所需的 maven 存储库。默认(在 UNIX 上)是 $HOME/.m2,但您可能不希望您的存储库在那里,因此您可以使用 M2 环境变量指定另一个位置,maven 将使用该位置而不是默认位置。