Skip to main content

Command Palette

Search for a command to run...

Maven + build system topics

Published
3 min readView as Markdown

1. Build Process

Build process means converting your source code into a runnable application.

In a Java project, this usually includes:

  • Compiling .java files into .class

  • Running unit tests

  • Packaging code into JAR or WAR

  • Managing dependencies

  • Deploying the artifact

Without a build process:

  • You compile files manually

  • You copy JARs by hand

  • You forget steps and make mistakes

With a proper build process:

  • One command does everything

  • Same result on every machine

  • Easy automation (CI/CD)

Think of it as a recipe. Same ingredients, same steps, same output.


2. Build Tools

Build tools automate the build process.

Common Java build tools:

  • Ant (old, procedural)

  • Maven (most popular, convention-based)

  • Gradle (modern, flexible)

What build tools do:

  • Compile code

  • Download dependencies automatically

  • Run tests

  • Package applications

  • Handle environments

Why build tools matter:

  • Team collaboration becomes easy

  • No “it works on my machine” issues

  • Essential for DevOps and CI/CD pipelines


3. What is Maven

Maven is a build automation and dependency management tool for Java projects.

Main ideas behind Maven:

  • Convention over configuration

  • Centralized dependency management

  • Standard project structure

Maven answers questions like:

  • Which libraries does my project need?

  • How to build my project?

  • How to package it?

  • How to share it with others?

When you use Maven:

  • You don’t download JARs manually

  • You don’t write long build scripts

  • You follow a standard structure

In real companies, Maven is everywhere.


4. Maven Phases

Maven works in lifecycle phases. Each phase does a specific job.

Main lifecycle phases:

  • validate – check project structure

  • compile – compile source code

  • test – run unit tests

  • package – create JAR/WAR

  • verify – check quality

  • install – store artifact in local repo

  • deploy – push artifact to remote repo

Important point:

  • If you run a later phase, Maven runs all earlier phases automatically

Example:

mvn package

This runs:
validate → compile → test → package

This makes builds predictable and reliable.


5. Maven Installation

To use Maven, you need:

  • Java (JDK)

  • Maven binary

  • Proper environment variables

Steps (high level):

  1. Install JDK

  2. Download Maven

  3. Set MAVEN_HOME

  4. Add Maven to PATH

  5. Verify using:

mvn -version

Once installed:

  • You can build any Maven project

  • Same commands work on Linux, Windows, macOS

This portability is why Maven is DevOps-friendly.


6. pom.xml file

pom.xml is the heart of a Maven project.

POM = Project Object Model

It contains:

  • Project details (name, version)

  • Dependencies

  • Plugins

  • Build configuration

Example responsibilities:

  • Tells Maven which libraries to download

  • Defines how the project should be built

  • Controls Java version

  • Configures testing and packaging

Key sections inside pom.xml:

  • <groupId> – organization

  • <artifactId> – project name

  • <version> – project version

  • <dependencies> – required libraries

  • <build> – build plugins

If pom.xml is wrong, the build fails.
If pom.xml is clean, everything works smoothly.


7. Maven Commands

Maven is command-driven.

Common commands you must know:

mvn clean

Deletes old build files

mvn compile

Compiles source code

mvn test

Runs unit tests

mvn package

Creates JAR or WAR

mvn install

Installs artifact locally

mvn clean install

Most commonly used in companies

Why commands matter:

  • Used in CI/CD pipelines

  • Used by Jenkins, GitHub Actions, GitLab CI

  • Same command works everywhere


Big Picture (Very Important)

How everything connects:

  • Build Process → what needs to happen

  • Build Tool → automates it

  • Maven → popular Java build tool

  • Phases → ordered steps

  • pom.xml → configuration brain

  • Commands → execution triggers

If you are aiming for Java backend, DevOps, or cloud roles, Maven is not optional.

More from this blog

T

The DevOps Journal

23 posts