In this tutorial I will explain you how to create multi-modules maven project in Eclipse. This kind of project is a good design when you want to group similar applications or projects and reduce the duplication in code.
A multi-module project is built from a parent pom that manages a group of submodules. In most cases, the parent pom is located in the project’s root directory and must have packaging of type
The submodules are regular maven projects and have packaging type different than pom, such as,
ear and maven build can be run on separate module’s pom file or on the parent’s pom file. By running the maven build on parent’s pom file will build all submodules.
Creating Multi-modules Project in Eclipse
Please follow below steps to create the multi-modules maven project.
First you have to create parent module then you need to create submodules.
Creating Parent Module
- Create a New maven project in Eclipse.
- Select Archetype as
- In next window input Group Id, Artifact Id etc. For example, Group Id –
com. roytuts, Artifact Id –
maven-multi-module-project, Version – by default auto populated or you can change.
- Once the module or project created successfully in the Eclipse, open the
pom.xmlfile and change the packaging type as
- Update the project: simply do
Maven -> Update Project.
So you saw how to create a parent module for this multi module maven project.
Now you need to create submodules. The packaging type for submodule depends on what type of project or module you need for your application.
Maven 3.6.3, Java at least 8, Eclipse at least 4.12
Now I will create two submodules in this application – email-service and user-service. I am going to the packaging type for each submodule is
- Do right click on the parent module –
New -> Other.
- In the Wizard window select
Maven -> Maven Module.
- In the next window input Module Name as user-service. Make sure that Parent Project selected as
- On next window select Archetype as
- In next window accept all defaults and click Finish. Now you will see in the parent project’s
(maven-multi-module-project)pom has been updated with
- Now open the user-service project’s pom.xml file and remove
<version/>tags. Because these two values will be inherited from parent project or module.
- Now create another module email-service in the similar way as you have created user-service.
- Remove the
<version/>tags from the pom.xml file.
- Now again you will see the parent’s pom file has been updated to include the
The project structure will look like similar to the below image.
Managing Dependencies and Plugins
Ideally you want to add dependencies and plugins into parent module or project from which each child module or project will automatically inherit those dependencies and plugins.
If you want to override any inherited dependency in child pom then you need to declare the same dependency in child’s pom file.
Building the Project
You can build the entire project with all modules from the parent pom file or you can also build the individual module from its own pom file.
Didn’t get the exact structure as shown in the above image?
Solution is highlighted in the below image:
3 thoughts on “Creating Multi-Modules Maven Project in Eclipse”
I have created modules as you have mentioned, but the hierarchy of folders as you have shown in the image is not something which eclipse shows. It shows a separate project folder for each module at the same level as the parent. Is there any setting for showing it in a hierarchy as child modules of the parent as you have shown?
Gautam: Have a look here: https://stackoverflow.com/q/9229651/5128464