Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create maven multi module project in Eclipse

 What is multi Module project?

A Multi Module project is used to manage a group of submodules. A multi-module project is built from an aggregator POM which is located in the project’s root directory and has a package type as pom. Child modules inherit from the parent pom.

In a multi-module project, using the single maven command you can build all the artifacts and maintain all the artifact versions in sync. Configuring a CI/CD pipeline is easy, one Jenkin job will do the job.

Let’s see it with an example. I am going to create a root project ‘platform’ and create two modules under this project.

a.   connectors

b.   transformers

Follow the below step-by-step procedure to build multi-module project in Eclipse.

Open Eclipse.

File -> New -> Other



Select ‘Maven Project’.


Click on Next button.

Select the check box ‘Create a simple project (skip archetype selection)’.



Click on Next button.


Set following fields.

a.   Group Id as com.sample.app

b.   Artifact Id as platform

c.    Version to 1.

d.   Packaging type should be pom

 


Click on Finish button.

 

Project hierarchy looks like below.



pom.xml

xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sample.app
platform
1
pom

When you open pom.xml, you can observe packaging type is pom. This pom is called the parent pom. That means it acts as a parent pom to all the projects underneath this project.

 

Let’s create two modules under this project.

a.   connectors

b.   transformers

 

Create connectors module

File -> New -> Other



Select ‘Maven Module’ and click on the Next button.



Select the check box ‘Create a simple project (skip archetype selection).

Set module name as connectors and set the parent project to platform.

 

Click on Next button.



Use default options (packaging is set to jar) and click on Finish button.



connectors project pom.xml is given below.

 

pom.xml

xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.sample.app
platform
1

connectors

As you observe pom.xml, parent portion is added with platform project details.

 

‘platform’ project pom.xml contains new module information.

xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sample.app
platform
1
pom

connectors


Create transformers module

Follow the same procedure as above. Post transformers module creation, you can observe new module ‘transformers’ is added to platform pom.xml.

xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sample.app
platform
1
pom

connectors
transformers


Total project structure is given below.



Open a terminal and navigate to the platform pom.xml file and execute the command ‘mvn clean install’. Once the command is executed successfully, you can observe two jar files (connectors-1.jar, transformers-1.jar) get created.


Previous                                                    Next                                                    Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Create maven multi module project in Eclipse

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×