Chapter 6. Creating a Multimodule Project

Now that we have already launched the rocket, let's explore more of it. In this chapter, we will develop a MyDistance application from the previous chapter as a multimodule Maven project and learn how to create multimodule projects, build, and run them. The topics covered in this chapter are as follows:

  • Introduction
  • Creating a parent project—POM
  • Creating a core module
  • Creating a webapp module
  • Building a multimodule project

Introduction

Software architecture states modularity as the degree to which a system's components may be separated and recombined. In software engineering, modularity refers to the extent to which a software/application can be divided into multiple modules to achieve the business goal. Modularity enhances manageability and reusability. The growing days has seen software getting more complex, and modularity is the need of the hour.

Multimodule projects consist of many modules that adapt to modularity. A multimodule project is identified by a parent/master POM referencing one or more .sub modules.

A multimodule project constitutes of the following:

  • Parent project POM: This glues and references all the other modules of a project
  • Modules: This includes submodules that serve different functions of the application and constitute the application

Parent POM is where you can put common dependencies in a single place and let other modules inherit it, that is, POM inheritance in modules. Usually, universal dependencies such as JUnit or log4j are the candidates of POM inheritance.

The mechanism by which Maven handles multimodule projects is referred to as reactor. The reactor of Maven's core has the following functions:

  • Collects all the modules to build
  • Sorts the projects (modules) into the current build order
  • Builds the sorted projects in order

The modules of the project are enclosed inside the <modules> </modules> tag by specifying each module with the <module> </module> tag. Similarly, the parents are enclosed inside the <parent> </parent> tag by specifying Maven coordinates.

Now, for illustration, we will take the MyDistance application from Chapter 5, Spicing Up a Maven Project, and develop it as a multimodule project. The modules of the project would be as follows:

  • Distance-main: This is the parent project, also known as parent POM, that glues and references different modules of the project, that is, distance-core and distance-webapp
  • distance-core: This module provides a simple distance conversion utility class
  • distance-webapp: This is a web interface in which you can input the units that depend on the distance-core module to perform a conversion and respond to the results

In the subsequent sections, we will get into the details of the preceding modules.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.128