Maven Tutorial
Maven in IDE
This tutorial will guide you through the installation and configuration of Maven on your system. We will cover the steps for Windows, macOS, and Linux operating systems.
Prerequisites:
Maven Installation Steps:
1. Download Maven:
Download the latest Maven release from the official website: https://maven.apache.org/download.cgi
Choose the binary archive appropriate for your operating system (e.g., .zip for Windows, .tar.gz for macOS/Linux).
2. Extract Maven:
Extract the downloaded archive to a directory of your choice. For example:
C:\Program Files\Apache Maven
/opt/apache-maven
This directory will be referred to as ${MAVEN_HOME}
.
3. Set Environment Variables:
Windows:
a. Open "Environment Variables" settings. You can search for "Environment Variables" in the Start menu or right-click on "Computer" -> "Properties" -> "Advanced system settings" -> "Environment Variables".
b. Create a new System Variable with the name MAVEN_HOME
and the value as the path to the extracted Maven directory (e.g., C:\Program Files\Apache Maven
).
c. Edit the Path
System Variable and add the following entry: %MAVEN_HOME%\bin
.
macOS/Linux:
a. Open a terminal window.
b. Open your shell profile file. For Bash, it's typically ~/.bashrc
or ~/.bash_profile
. For Zsh, it's ~/.zshrc
. Use a text editor to open the file, e.g., nano ~/.bashrc
.
c. Add the following lines to the file:
export MAVEN_HOME=/opt/apache-maven export PATH=$PATH:$MAVEN_HOME/bin
Replace /opt/apache-maven
with the actual path to the extracted Maven directory.
d. Save and close the file.
e. Run source ~/.bashrc
(or the appropriate file for your shell) to apply the changes to the current session.
4. Verify Maven Installation:
Open a new terminal or command prompt and run the following command:
mvn -v
If the installation was successful, you should see output similar to the following:
Apache Maven 3.8.4 (ea4b354...e3973d5...) Maven home: C:\Program Files\Apache Maven\bin\.. Java version: 14.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-14.0.2 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Congratulations! You have successfully installed and configured Apache Maven on your system.
Configuring system environment variables for Maven:
M2_HOME
and PATH
for system-wide Maven access.export M2_HOME=/path/to/apache-maven-x.y.z export PATH=$PATH:$M2_HOME/bin
Configuring Maven repositories for dependency resolution:
pom.xml
:<repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories>