What is Maven?
In brief: Maven ⇔ npm + Vite + standardized project layout
What does this mean? Maven is often likened to that of a package manager (like npm) that manages dependencies, which is indeed one of the major features it has. However, it’s more accurate to call it a build system which is where an analogy like Vite comes into play.
While the average developer doesn’t need to know how Vite works, they would be very sad if they had to manually configure a dev server, TypeScript/JSX transforms, bundling, path resolution, and a bunch of other terms that probably don’t make sense. Vite abstracts all of that away into a neat little config file. This is beauty of Maven, providing centralized and predictable builds for Java systems, with features like testing, lifecycle phases, source control integration, and archetypes.
So then what does “standardized project layout” mean? Well, Maven turns out to be quite opinionated—npm doesn’t care how your project is structured—but Maven does. It has specific folder layouts and strong conventions, with the official philosophy being “convention over configuration.” This is pretty great when diving into a new codebase.
This standardized project layout does require the existence of a pom.xml file, however.
pom.xml (POM)
Referring to the Project Object Model, this file is the projects definition file which defines what the project is, what it depends on, what plugins to run, and what lifecycle customizations exist. I would liken it to a package.json, but in reality it’s the heart of the project by encoding testing instructions, compilation instructions, bundling, etc.
At a minimum, the file demands
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>But it’s just as likely to include things like
<project> - this is the root tag of the file;
<modelVersion> - defining which version of the project object model to be used;
<name> - name of the project;
<properties> - project-specific settings;
<dependencies> - this is where you put your Java dependencies. Each one needs a <dependency>, which has:
- <groupId>;
- <artifactId>;
- <version>;
<plugins> - for third-party plugins that work with Maven.The Build Lifecycle
A well-defined sequence of phases that a Maven build goes through. The phases are:
validate- is the project correct?compiletest- test the compiled source with a unit-testing frameworkpackage- move the compiled code into a distributable format (i.e. JAR)verify- runs checks on the results of the integration testsinstall- install the package into the local repositorydeploy- copy the final package to the remote repository for use
A phase can be invoked with mvn <phase_name>.
Let’s use it
Refer to Java Fundamentals