Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Apache Maven Complete Guide: Concepts, Installation, settings.xml, and First Build

Originally published on 2010-04-14; fully revised and updated.

Apache Maven is a build and project management tool centered around the pom.xml. This guide is for developers and DevOps engineers who need a practical baseline: what Maven does, how installation works, how settings are managed, and how to create and build a first project.

Maven introduction

Useful original resources: Maven downloads at maven.apache.org/download.html, and the original linked video at YouTube.

What Maven is and why DevOps teams use it

Maven is an Apache tool that standardizes how projects are built, tested, packaged, and published. It uses a declarative model in pom.xml so teams can share a common build process across repositories and environments.

  • Defines project metadata (group, artifact, version, packaging).
  • Resolves dependencies from local and remote repositories.
  • Runs standard lifecycle phases such as compile, test, and package.
  • Uses plugins for checks, reports, releases, and deployment workflows.

Maven philosophy: conventions over custom scripting

The original post compared Maven with Ant. That distinction is still useful: Maven emphasizes shared conventions and lifecycle phases, while Ant is task-oriented and script-driven.

AspectMavenAnt
Build styleDeclarative model via pom.xmlImperative target/task scripting
Project structureConvention-based default layoutUser-defined layout
DependenciesBuilt-in repository and transitive dependency resolutionUsually manual or via additional tooling
Team consistencyHigh, because lifecycle is standardizedVaries by project script design

How a Maven build flows

When you run a Maven goal, Maven reads the POM, resolves artifacts, and executes lifecycle phases using configured plugins.

flowchart TD
    A[Run mvn package] --> B[Read pom xml]
    B --> C[Resolve dependencies in local repository]
    C --> D{Artifacts missing}
    D -- yes --> E[Download from remote repository]
    D -- no --> F[Use local cache]
    E --> G[Execute lifecycle phases]
    F --> G
    G --> H[Run tests and package artifact]
    H --> I[Install artifact locally when requested]

Install Maven on Windows, Linux, and macOS

The original article used Maven 2.2.1 and legacy OS examples. The modern process is still the same at a high level: install a JDK, install Maven, set environment variables, and verify from the command line.

  • Install a JDK (JRE alone is not enough).
  • Download Maven from the official download page.
  • Extract Maven to a stable path.
  • Set JAVA_HOME and add Maven bin to PATH.
  • Verify using mvn -version.

Example: Linux or macOS shell

export JAVA_HOME=/path/to/jdk
export M2_HOME=/opt/apache-maven
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH
mvn -versionCode language: JavaScript (javascript)

Example: Windows command prompt

set JAVA_HOME=C:\Path\To\JDK
set M2_HOME=C:\Tools\apache-maven
set PATH=%JAVA_HOME%\bin;%M2_HOME%\bin;%PATH%
mvn -versionCode language: JavaScript (javascript)

Configure environment-specific behavior with settings.xml

Maven settings belong outside project source code. Typical uses include proxy setup, repository mirror configuration, and credentials for artifact download or deployment.

  • Global settings: $M2_HOME/conf/settings.xml
  • User settings: ${user.home}/.m2/settings.xml
<settings>
  <localRepository>/opt/maven-repo</localRepository>

  <mirrors>
    <mirror>
      <id>internal-mirror</id>
      <mirrorOf>*</mirrorOf>
      <url>https://repo.example.com/repository/maven-public/</url>
    </mirror>
  </mirrors>

  <servers>
    <server>
      <id>internal-mirror</id>
      <username>build-user</username>
      <password>${env.MAVEN_REPO_PASSWORD}</password>
    </server>
  </servers>
</settings>Code language: HTML, XML (xml)

Keep credentials out of pom.xml and out of source control; prefer environment variables or a secrets manager integrated with CI.

Create your first Maven project

The original article used archetype:create in its example. A commonly used modern pattern is archetype:generate with explicit coordinates.

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=falseCode language: JavaScript (javascript)
cd my-app
mvn test
mvn package
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
</project>Code language: HTML, XML (xml)

Core POM identifiers to remember: groupId, artifactId, version, and packaging.

Common Maven commands at a glance

CommandWhat it doesTypical use
mvn cleanRemoves previous build outputFresh local or CI build
mvn testCompiles and runs testsValidate code changes quickly
mvn packageBuilds artifact (for example JAR or WAR)Create deployable package
mvn installPublishes artifact to local repositoryLocal dependency reuse across projects
mvn deployPublishes artifact to remote repositoryRelease or CI/CD publication
mvn dependency:treePrints resolved dependency graphTroubleshoot conflicts and transitive pulls

Best practices and common pitfalls

  • Pin critical plugin versions in your POM for reproducible builds.
  • Do not commit credentials in POM or settings files.
  • Use a repository manager mirror in enterprise environments to improve control and caching.
  • Use mvn dependency:tree early when debugging classpath issues.
  • Keep CI and local JDK/Maven toolchains aligned to reduce environment drift.
  • Treat legacy Maven tutorials carefully, especially those tied to very old Maven and OS versions.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Maven Learning Resources: A Practical Study Plan with the Better Builds with Maven PDF

The original post shared one Maven book link. This revised guide preserves that resource and adds a practical learning workflow, comparison table, and hands-on Maven commands.

Read More

Maven CLI Options Reference: Practical Flags, Comparisons, and Command Examples

A structured Maven command-line reference for CI/CD and local builds, including option comparisons, workflow guidance, and ready-to-use mvn commands. Based on the original 2013 cheatsheet, updated for readability and operational use.

Read More

Maven2 Web Application Setup: Legacy Step-by-Step Guide with Build, Jetty, and Site Reporting

A practical Maven2-era walkthrough for creating a Java web app, running core build goals, and generating docs and reports from pom.xml. This revision keeps the original workflow but adds structure, comparisons, and implementation-ready snippets.

Read More

Maven Clover for Distributed Java Applications: Instrument, Collect, and Aggregate Coverage

Learn a practical Clover + Maven workflow for distributed test environments. This walkthrough covers instrumentation, remote execution, coverage file collection, and final report generation.

Read More

Maven Reporting Plugins: Configure Site Reports in pom.xml (All, Selective, and reportSets)

Maven reporting plugins generate project documentation during the site lifecycle and are configured in the reporting section of pom.xml. This guide shows how to run all reports, select specific ones, and structure reportSets cleanly.

Read More

Maven Properties Reference: project.*, settings.*, env.*, and Custom POM Values

Maven properties are the backbone of reusable, environment-aware builds. This revised reference explains major property sources, interpolation flow, and practical commands for inspecting real values.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x