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:
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 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:
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 classdistance-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 resultsIn the subsequent sections, we will get into the details of the preceding modules.
3.144.17.128