Maven POM template - an example
A pom.xml file to get you started with Maven
When you’re kickstarting a new Java project, you might find yourself getting stuck at the first hurdle. How do you set up your brand new project with Maven?
If you’re using Maven to build your project (and many teams use it, so you’re in good company!), you’ll find that you need to create something called a pom file. What’s a pom file? It’s an XML file – usually called
pom.xml – where you tell Maven all about your project, and declare all of your dependencies.
You’re probably thinking, what does a pom file look like? And is there a basic beginner pom file that you can use?
Fortunately, most IDEs can create your pom file for you. Just create a new Java project and follow the wizard steps. But, if you’re doing this on your own, don’t worry! You don’t need to write one from scratch. We’ve prepared an example pom file for you.
Maven pom.xml template
Here’s an example pom.xml that you can use to kickstart your next project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>your-project-name</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>your-project-name</name> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- Your dependencies go here, like this! --> <!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> --> </dependencies> <build> <plugins> <!-- Your plugins go here! --> </plugins> </build> </project>
You can add this into your project’s folder as
pom.xml. Don’t forget to:
Add the dependencies that you need in the
Add any plugins you need in the
Start adding your source code into
Alternative ways to bootstrap a Maven project
Are there any other ways to generate this pom file? Yes, many! Here are some of the ways:
Using your IDE. Most Java IDEs like IntelliJ or Eclipse include wizards or templates which can generate your pom file for you.
Spring has an online wizard called the Spring Initializr, which bootstraps a new Spring or Spring Boot project, and includes a ready-made pom file. Of course, this is mostly useful if you’re using the Spring framework.
Quarkus also has an online wizard at code.quarkus.io to bootstrap a new project. Again, only applies if you’re using Quarkus.
From the command line, Maven’s own
mvn archetype:generatecommand will create a new project for you from an archetype (template).
But for now, I hope you found this example pom.xml useful!