Build Tools: Maven
The Project Object Model (pom.xml)
Every Maven project has a pom.xml file at its root. It declares the project's coordinates (group, artifact, version), the dependencies it needs, and any plugins that customize the build. Maven reads this file, resolves every dependency (and their own transitive dependencies) from a remote repository such as Maven Central, and caches them locally so subsequent builds are fast.
A minimal pom.xml with one dependency
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-app</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>The groupId, artifactId, and version together uniquely identify your project (and every dependency you pull in) inside a Maven repository — this triplet is often called the "GAV coordinates."
The Standard Directory Layout
Maven follows a convention-over-configuration philosophy: as long as your files live in the expected places, you don't need to tell Maven where anything is.
Standard Maven project structure
demo-app/
├── pom.xml
└── src/
├── main/
│ ├── java/ (your application source code)
│ └── resources/ (config files, properties, static assets)
└── test/
├── java/ (unit and integration test source code)
└── resources/ (test-only config files)The Build Lifecycle
Phase | What It Does |
compile | Compiles the source code in src/main/java |
test | Runs unit tests using a testing framework such as JUnit |
package | Packages compiled code into a distributable format, e.g. a JAR |
install | Installs the package into the local repository (~/.m2), for use as a dependency in other local projects |
Running a build from the command line
# remove previous build output, then compile, test, and package/install mvn clean install
This single command deletes the previous target/ directory, recompiles everything, runs the full test suite, packages the result into a JAR, and installs that JAR into your local repository so other local projects can depend on it.