Introduction

Best resources about Apache Maven are from Sonatype Maven Reference Book and Maven By Example. However, the exhaustive details in these books may confuse and overwhelm the beginners.

This tutorial series tries to explain the Apache Maven concepts and workflow in easy steps. Focus is to explain Apache Maven with simple examples and easy explanations for benefit of beginners and intermediate users.

As objective of the tutorial is to explain Apache Maven concepts and its working, the Java examples we use in the tutorial are extremely simple and small, so that focus is more on Maven rather than Java projects. Also, most of chapters use command line interface (CLI) to explain the Maven so that beginners can to know Maven up close. Only the last couple of chapters use GUI where we use Maven to build Eclipse projects.

About Apache Maven

Apache Maven is a project management tool which takes care of following aspects of project management.

  • builds the project including preprocessing, compilation, packaging, testing, and distribution.

  • automates the project dependency management.

  • generate project reports, documentation and project web site.

Comparision with Apache Ant and Ivy

The other popular build system, Apache Ant with Apache Ivy can also do what Maven does. The advantages of Maven over Ant are:

Convention over Configuration

Ant follows Configuration over Custom approach and developers who like to configure the build system from scratch and wants a flexible build process prefer Ant. In contrast, Maven follows Custom over Configuration approach, which means the project has to fall into certain customs or best practices enforced by Maven. It is the default choice for the developers who don’t mind adapting to certain customs and don’t want spend time on build system.

Less Configuration

Since Maven predefines majority of the build process there is less to configure and in size, Maven build file is typically one tenth of Ant build file. Less configuration also means that developers can focus on project rather than tinkering with the build system.

It’s some thing like this: when it comes to Ant, you have to setup the entire build system whereas in Maven, experts have already setup the build system for you.

 
 

Easy to Learn

Ant build system involves two modules - Apache Ant and Apache Ivy. It comes with a steep learning curve as everything has to be put together from scratch. Learning Maven, too, involves some effort. But, once we are through with its concepts, project management becomes quite easy as configuration is minimal.

Portable

Maven is highly portable across projects and platforms. As Maven enforces certain customs, we can easily move between Maven projects without bothering much about the builds whereas in Ant projects, we need to spend some extra time with build files to know the configuration and the flow. It is often said, you see a mall and you have seen them all, similarly once you build a Maven project, you can manage any Maven project.

Is it Worth the Effort

Normally, a couple of things puts off beginners from Apache Maven.

Complicated terms and concepts

To define certain concepts, Maven uses complicated terms such as coordinates, artifacts, archetype, assemblies, lifecycle phases, project object model, Mojao etc., and beginners find it difficult to comprehend them.

Though Maven developers picked strange terms, the concepts behind them are simple and no much effort is required to understand them.

 
 

Project directory structure

The directory structure of an IDE generated project differs from a Maven project, many who comes from Ant background like to use the existing project structure in Maven.

Yes, it is possible to use existing project structure in Maven and later in the guide, we will show how. However, we strongly suggest you to go with Maven enforced structure as there is much to gain.

Endless downloads

Sometimes even a simple build seems to download lot of items from Internet.

A workable Maven setup requires just about 40 MB of downloads - Maven Core 8MB and core plugins 30MB. After that, download depends upon the additional artifacts (plugins and dependencies) we request. Maven stores artifacts in a local repository and reuses them effectively. Only when a artifact is not found in the local repository it is downloaded and as repository grows there will be less and less downloads.