Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of the JAVA_HOME, M2, and M2_HOME variables

Tags:

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

like image 512
Liza Tjaica Avatar asked Apr 25 '13 19:04

Liza Tjaica


People also ask

What should be the environment variable M2_HOME be set to?

Set M2_HOME & PATH Create an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH.

What are PATH variables used for?

The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/. profile file.

Why do we need to set PATH variable in Java?

Why Do You Set A Java Path? The path is the most important environment variable of the Java environment which is used to locate the JDK packages that are used to convert the java source code into the machine-readable binary format. Tools like javac and java can be used by setting the path.

What is PATH and JAVA_HOME?

JAVA_HOME and PATH are variables to enable your operating system to find required Java programs and utilities.


2 Answers

JAVA_HOME should 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_HOME itself should not be added to PATH. You should add JAVA_HOME/bin to be able to run commands from this directory without specifying the concrete path.

M2_HOME is a home of Maven. It is used by script mvn (or mvn.bat on Windows).

like image 146
AlexR Avatar answered Sep 23 '22 17:09

AlexR


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

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

Windows environment variable window

like image 28
prashantsunkari Avatar answered Sep 21 '22 17:09

prashantsunkari