Book Image

Apache Maven Cookbook

Book Image

Apache Maven Cookbook

Overview of this book

Table of Contents (18 chapters)
Apache Maven Cookbook
About the Author
About the Reviewers


Apache Maven Cookbook describes the features of Apache Maven through a series of recipes. This book will help you understand what Apache Maven is and allow you to use its features with the help of complete and working examples.

What this book covers

Chapter 1, Getting Started, covers the installation of Apache Maven on Microsoft Windows, Mac OS X, or Linux, as well as creating and building your first project with it. The chapter also details the steps to install prerequisite software required for Maven.

Chapter 2, IDE Integration with Maven, focuses on configuring popular IDEs with the help of Maven and running Maven projects in them. Eclipse, NetBeans, and IntelliJ IDEA are the three IDEs covered in this chapter.

Chapter 3, Maven Lifecycle, covers the life cycle of Apache Maven and explores the concept of phases and goals. It also describes how a user can use profiles to customize builds.

Chapter 4, Essential Maven Plugins, describes the Maven plugins, which are essential to build a project. For each plugin, the various configuration options are also explored.

Chapter 5, Dependency Management, explores the various types of Maven dependencies, and delves into downloading and getting reports on them. It also talks about how to handle network issues during a dependency download.

Chapter 6, Code Quality Plugins, covers the support provided for various code quality tools, such as Checkstyle, PMD, FindBugs, and Sonar. The configuration options for each plugin as well as generating reports are also explored.

Chapter 7, Reporting and Documentation, covers the reporting features of Maven. The site plugins and the various reports supported by it are described in detail.

Chapter 8, Handling Typical Build Requirements, explores the features provided by Maven to handle builds of selective sources and the inclusion of selected resources. It also describes how to use the command line and help features of Maven along with interfacing with software configuration management systems.

Chapter 9, Multi-module Projects, describes the support required to build large projects with multiple modules. Maven support for aggregated builds and defining parent-child relationships is also described here.

Chapter 10, Java Development with Maven, describes the building of different types of java artifacts like Jar, War and Ear. It also describes Maven support to run projects in Jetty and Tomcat.

Chapter 11, Advanced Maven Usage, explores the advanced features of Maven, such as creating distributions and enforcing rules. It also describes how to make a project release.

What you need for this book

To run the various recipes in this book, the following are required. Unless otherwise mentioned, it is best to have the latest version of the software suggested here:

  • A computer with one of the three operating systems, such as Microsoft Windows, Mac OS X or Linux, and preferably recent/supported versions

  • Java—specifically Java Development Kit (JDK)

  • Apache Maven

  • Git—for examples related to version control systems

  • One or more of the following IDEs:

    • Eclipse

    • NetBeans

    • IntelliJ IDEA

Who this book is for

Apache Maven Cookbook is intended for those of you who are seeking to learn what build automation is and how Apache Maven can be used for this purpose. It is also meant for you if you're familiar with Maven, but would like to understand the finer nuances of it to solve specific problems. It is also a good book if you're looking for ready-made recipes to solve specific use cases.


In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The preceding output will still not tell you where your Java is installed, which is required to set JAVA_HOME."

A block of code is set as follows:


When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<settings xmlns=""

Any command-line input or output is written as follows:

brew install maven

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "To persist this, set Environment Variables... using the Control Panel option, as described later for the M2_HOME variable."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.