Start a Project
Call Us  0161 505 1048


Getting Started With Maven

17 February 2016
Maven logo | Neon

Maven is a popular dependency and build tool within the Java ecosystem, however, it can be daunting to start with. This guide is targeted at developers that have previously used tools such as npn, gulp and grunt.

This article aims to give you key information and useful resources about maven for the most frequent scenarios.

Install Maven

The installation of maven is relatively simple; download, extract and place the appropriate bin folder onto your PATH variable. The instructions on the project’s own installation page should be enough to get a point where the terminal command mvn works. You can check everything is expected by getting maven to print version


mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: ~devbinapache-maven-3.x.xbin..
Java version: 1.8.0xx, vendor: Oracle Corporation
Java home: C:Program FilesJavajdk1.8.x
Default locale: en_GB, platform encoding: Cp1252
OS name: “windows 10”, version: “10.0”, arch: “amd64”, family: “dos”

Generate the pom.xml

The Project Object Model (POM) file is the key file inside a maven project. It provides information about the project itself, how it is configured and its dependencies. To get started you can allow maven to use the quick start template. Additional details about this quick start template can be found here:

mvn archetype:generate

This command doesn’t need to be run within a project folder as it will generate a folder named “my-app” which will contain all the other generated files.

At this point, you will have a pom.xml file with the following content.

The groupId and artifactId identify this project and its output. The packaging tag tells Maven how the final output of the project will be packaged. You will typically see jar and war as values. These two types of packaging are very popular in the Java ecosystem. You may also see the type pom. This is used to create a package of submodules and allow cross artefact dependencies between artefacts of the same group.

Using Maven for the First Time

With a valid POM and maven directory structure you will now be able to package the project.


mvn package

After running this command, you will have a folder “target” which will include your classes packaged in a jar file.

Fix Your Warnings

If you look carefully at the output of Maven you will notice a warning about the build being platform dependent.

[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

Simply setting the source encoding removes this warning. This can be done by adding the following to the node.


We will revisit the use of properties later in this guide.


A dependency is identified by its GroupId and ArtifactId. Many projects will give you an example XML node to add to your pom.xml document. For example junit gives this dependency node in its wiki:


This is added inside the node.

Simple dependencies often only have one artefact but more complex or well modularised dependencies could have many artefacts to select. It becomes tedious (and error prone) to specify the version number using a literal value.

We can add a node to properties


and use that throughout our POM like so:


Finding Dependencies

The Maven Central repository contains a large number of dependencies to select from. If it does not include the dependency you are looking for then you should consider installing the jar locally or hosting your own private Maven repository.

Packaging Everything in a Single Executable Jar

Often it is desirable to package your project into a single jar with all the required dependencies included. This can be done by using the assembly plugin. The first step is to update your POM to include your main class in the assembly configuration by adding the following node to




mvn assembly:single

You can now run the jar with the following command:


java -jar target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jar
Hello World!


In this guide you have learnt the basics of Maven, details about the POM file, how to use properties in the pom file to keep it as DRY as possible and learnt how to find and specify dependencies.

Tweet us @createdbyneon if you have any further thoughts about Maven and check out our web development services that could help you build a strong competitive advantage.

Related Items

How to create landing pages that convert

What is a content delivery network?

What is mobile-first design?

We are here to help

Want to be at the top of the search ranks? How about a website that’ll give your audience a great experience? Or maybe you’re looking for a campaign that’ll drive more leads? Get in touch to find out how we can help.

Start a project
The design and dev team making notes | Start a project with Neon | Neon
Employee on telephone
Group work
Designer laughing
Computer typed on
Sausage dog
Writing on white board
Designer planning sitemap
Employee posting notes on board
Developer working
Group photo of CEO and Brand Ambassador
Employee in meeting
Employee in Meeting

Stay up to date

Privacy Policy

© Neon Digital Agency Ltd 2021. Part of

Inc & Co Logo