Maintaining complex classpaths and manually compiling files is painful. That’s where build tools come in.
Absolutely! Here’s a simple and complete guide to help your readers set up Maven on their system (both Windows and Linux), followed by verifying the installation.
Maven Setup Instructions
To build and manage Java projects efficiently, Maven is a must-have. Here’s how to set it up on your system.
Windows Setup
1. Download Maven
Go to the official Apache Maven site: https://maven.apache.org/download.cgi
- Download the binary zip archive (e.g.,
apache-maven-<version>-bin.zip
) - Extract it to a folder, e.g.,
C:\Programs\apache-maven-<version>
2. Set Environment Variables
- Open Windows Powershell.
- Set the installation path as follows:
setx MAVEN_HOME "C:\Programs\apache-maven-<version>"
setx PATH "%PATH%;%MAVEN_HOME%\bin"
3. Verify Installation
Open Command Prompt and run:
mvn -v
You should see Maven version info.
Linux Setup
1. Download Maven
wget https://downloads.apache.org/maven/maven-3/<version>/binaries/apache-maven-<version>-bin.tar.gz
2. Extract the Archive
tar -xvzf apache-maven-<version>-bin.tar.gz
sudo mv apache-maven-<version> /opt/maven
3. Set Environment Variables
Edit your shell profile (~/.bashrc
, ~/.zshrc
, etc.) and add:
export MAVEN_HOME=/opt/maven
export PATH=$MAVEN_HOME/bin:$PATH
Apply the changes:
source ~/.bashrc # or source ~/.zshrc
4. Verify Installation
mvn -v
You should see output with the Maven version, Java version, and JAVA_HOME path.
Now Lets add below in pom.xml
:
You’re Ready
<!-- pom.xml -->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</project>
Run:
mvn package
JAR gets built inside target/
.