Use "parent" in Maven Project File

This section provides a tutorial on how to use 'profile' in Maven project file to provide options to control the build process.

If you want to organize a large Java development project into multiple modules, you can use the "parent" entry to link module-level pom.xml project files to the top-level project file. Here is how I created a two-module Java project:

1. Create the top-level directory and pom.xml file:

herong$ mkdir hello
herong$ vi hello/pom.xml

2. Define "packaging" as "pom" and a list of "modules" in the top-level pom.xml:

<?xml version="1.0" encoding="utf-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>herong</groupId>
  <artifactId>hello</artifactId>
  <version>1.0.1</version>
  <name>Hello</name>
  <description>Hello project</description>
  <packaging>pom</packaging>
  <properties>
    <source>1.8</source>
    <target>1.8</target>
  </properties>
  <modules>
    <module>module-a</module>
    <module>module-b</module>
  </modules>
</project>

3. Create module-level sub-directories and pom.xml files:

herong$ mkdir hello/module-a
herong$ vi hello/module-a/pom.xml

herong$ mkdir hello/module-b
herong$ vi hello/module-b/pom.xml

4. Reference the top-level project as "parent" in the module-a pom.xml file:

<?xml version="1.0" encoding="utf-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>herong</groupId>
    <artifactId>hello</artifactId>
    <version>1.0.1</version>
  </parent>
  <artifactId>hello-mod-b</artifactId>
  <name>Hello Module B</name>
  <description>Hello project - Module B</description>
  <properties>
    <maven.compiler.source>${source}</maven.compiler.source>
    <maven.compiler.target>${target}</maven.compiler.target>
  </properties>
</project>

5. Run "mvn" command on the top-level directory. Maven will automatically compile and build all sub-modules:

herong$ cd hello
herong$ /Library/Maven/apache-maven-3.6.2/bin/mvn --fail-at-end package
[INFO] ------------------------------------------------------------------
[INFO] Reactor Summary for Hello 1.0.1:
[INFO]
[INFO] Hello ........................................ SUCCESS [  0.005 s]
[INFO] Hello Module A ............................... SUCCESS [  0.810 s]
[INFO] Hello Module B ............................... SUCCESS [  0.525 s]
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] Total time:  1.436 s

Table of Contents

 About This Book

 Macintosh OS (Operating System) History

 macOS Operating System

 macOS File Systems

 macOS Network Connections

 System and Application Processes

 Keychain Access - Password Manager

 Keychain Access - Certificate Manager

 Productivity Tools on macOS

 Programming Tools on macOS

 Apache Web Server on macOS

Develop and Run Java Applications

 Install JDK (Java Development Kit) on macOS

 Run Java Applet in Safari

 Install Apache Maven on macOS

 The Simplest Maven Project File

 Use "profile" in Maven Project File

Use "parent" in Maven Project File

 Install FOP (Formatting Objects Processor) on macOS

 Install Tomcat Java EE Server on macOS

 Full Version in PDF/EPUB