Yasitha Bandara
Yasitha Bandara

Reputation: 351

maven work without environment variable in ubuntu

I'm currently working on an ubuntu pc.I created maven project in eclipse and Build it by giving the goals "clean install". it created war files.

But when I search maven home environment variable using commands printenv it shows nothing like M2_HOME in the output list.

when I give the command echo $M2_HOME it shows blank line.

when I give the command mvn --version it gives me the flowing output

Apache Maven 3.3.9 
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation 
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-109-generic", arch: "amd64", family: "unix"

my question is, can maven work without environment variable?

Upvotes: 0

Views: 481

Answers (2)

Vasan
Vasan

Reputation: 4956

All Maven needs to work is the path to Java in your PATH environment variable. This is the minimum requirement. It is able to derive all the other HOME variables for its own use. On top of this, if you want to be able to run maven from any directory (rather than chdiring every time into maven's bin folder), you can add Maven's own bin folder also to PATH.

Note: The M2_HOME variable is actually being removed in maven 3.5.0. So it should not be used anymore.

Upvotes: 1

ziesemer
ziesemer

Reputation: 28697

can maven work without environment variable?

Yes - and you just proved it. :-) By default, with your distribution, /usr/share/maven is your $M2_HOME*.

If you navigate to a directory containing a pom.xml and run mvn clean install, you should also get a successful build.

2 additional notes:

First, Eclipse (at least Eclipse for Java EE Developers) includes its own embedded Maven installation by default - so you don't necessarily even need Maven to be installed at the OS level. If you have both, depending upon how things are configured, you may end up using the same or separate copies of local repositories, etc.

Second, and to expand upon the above * - at least as of Maven 3.5.0, M2_HOME is no more. As per https://maven.apache.org/docs/3.5.0/release-notes.html :

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.

See also:

To summarize the above reference, what really matters is your PATH variable - not M2_HOME.

Upvotes: 3

Related Questions