Maven is an open-sourced Java-powered project management tool for building and dependency management of Java projects. This post will show how to install Maven on Mac OS X or Unix/Linux system.

About Apache Maven

Maven is an open-source Java-powered project under Apache. Based on the concept of a project object model (POM), Maven is a project management tool for building and dependency management of Java projects.

Main features of Maven

Maven can help developers do the following tasks:

  • Construct projects
  • Document generation
  • report
  • rely on
  • SCMs
  • release
  • distribution
  • Mailing Lists

Install Maven on Mac OS X

Step 1:

Download Apache Maven from maven.apache.org. Choose one release of Maven to download. Here, I downloaded the Apache Maven 3.6.3 release.

Step 2:

Unzip the downloaded maven file in any directory using the unzip or tar command.

tar xzvf apache-maven-3.6.3-bin.tar.gz

or

unzip apache-maven-3.6.3-bin.zip

Here, I would recommend moving the folder apache-maven-3.6.3 to /usr/local/maven/ , it’s convenient to manage files.

#create a directory 
$sudo mkdir /usr/local/maven   
#mv apache-maven-3.6.3 to /usr/local/maven/ named as maven-3.6.3
$sudo mv apache-maven-3.6.3 /usr/local/maven/maven-3.6.3

Step 3:

Add the bin directory of the created directory maven-3.6.3 to the PATH environment variable.

$vim ~/.bash_profile

Then, add the bin directory of the created directory maven-3.6.3 to the PATH in the file.

export M3_HOME=/usr/local/maven/maven3.6.x
export PATH=$M3_HOME/bin:$PATH

Save and quit the ~/.bash_profile file.

Step 4:

To activate the PATH environment variable.

$ source ~/.bash_profile

The end:

Check if Maven installed succeed by type the mvn -v command in terminal.

If Maven installed succeed on Mac OS X, you will see the result like:

$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven/maven-3.6.3
Java version: 13.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home

In fact, as to install Maven on Unix or Linux system, it can be done by the same method.

Conventional configuration

Maven advocates the use of a common standard directory structure. Maven uses the principle of convention over configuration, and everyone follows this directory structure as much as possible. As follows:

table of Contentspurpose
$ {basedir}Store pom.xml and all subdirectories
$ {basedir} / src / main / javaProject java source code
$ {basedir} / src / main / resourcesProject resources, such as property files, springmvc.xml
$ {basedir} / src / test / javaTest classes for the project, such as Junit code
$ {basedir} / src / test / resourcesTesting resources
$ {basedir} / src / main / webapp / WEB-INFweb application file directory, web project information, such as web.xml, local pictures, jsp view
$ {basedir} / targetPackaging output directory
$ {basedir} / target / classesCompile output directory
$ {basedir} / target / test-classesTest compilation output directory
Test.javaMaven will only automatically run test classes that conform to that naming rule
~ / .m2 / repositoryMaven default local repository directory location