Setting up Maven for development

To build a Java project you will need the tool Maven installed. Maven is a build automation tool that manages how a Java project is built and the it’s dependencies. You can find out more about Maven here. This page provides details around how to install Maven.

If there is anything missing or not clear in this guide, please leave a comment below.

Installing on Mac

  1. Firstly, you will need to download the ‘Binary Zip Archive’ of Maven from here: https://maven.apache.org/download.cgi
  2. Once the zip has been downloaded, extract the folder to a location of your choosing (Such as /usr/local)
  3. Once you have extracted the folder, update the PATH so that it contains the path to the bin folder of the extracted Maven folder (For example adding /usr/local/apache-maven-3.5.4/bin). You can find more details on where and how to update your path to point to the bin folder here https://www.architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/
  4. Additionally, Maven needs to know where Java is installed so you will need to create a new enviromental variable named JAVA_HOME that will need to point to the root folder of your installed Java SDK folder (For example: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home). Do this by adding export JAVA_HOME=<java_sdk_location> to your .BASH_PROFILE or .zshrc.
  5. With the installation complete, PATH updated and JAVA_HOME set, open up a terminal window (Found in /applications/utilities folder) and enter mvn -v. You should see output similar to this to indicate Maven is installed and ready to go:

Maven installed on Mac

Installing on Windows

  1. Firstly, you will need to download the ‘Binary Zip Archive’ of Maven from here: https://maven.apache.org/download.cgi
  2. Once the zip has been downloaded, extract the folder to a location of your choosing (Such as Program files)
  3. Once you have extracted the folder, update the environmental variable PATH so that it contains the path to the bin folder of the extracted Maven folder (For example adding C:\Program Files\apache-maven-3.5.4\bin). You can find more details on where and how to update your path to point to the bin folder here https://www.computerhope.com/issues/ch000549.htm
  4. Additionally, Maven needs to know where Java is installed so you will need to create a new enviromental variable named JAVA_HOME that will need to point to the root folder of your installed Java SDK folder (For example: C:\Program Files\Java\jdk1.8.0_181)
  5. With the installation complete, PATH updated and JAVA_HOME set, open a command line window (Search for cmd in the Start section) and enter mvn -v. You should see output similar to this to indicate Java is installed and ready to go:

Maven installed on Windows

Frequently asked questions

When I run mvn -v it tells me it’s not recognised

If you have installed Maven but are receiving errors in your terminal or command about Maven not being available it is likely that the environmental variable for your system named PATH is missing details of where your copy of Maven is installed.

You can learn more about updating your environmental variables here: https://www.computerhope.com/issues/ch000549.htm and more about installing Maven here: https://maven.apache.org/install.html

Comments