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 projects. The packaging type in parent pom file should pom.

Please follow below steps to create the multi-modules maven project.

  1. Create New maven project in Eclipse menu. Select Archetype as maven-archetype-quickstart. In next window input Group Id, Artifact Id etc. For example, Group Id – jeejava, Artifact Id – spring-microservices, Version – by default auto populated. Now open the pom.xml file and change the packaging type as pom. If you find any problem on the project then simply do Maven -> Update Project.
  2. Now do right click on the spring-microservices project and click 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 spring-microservices. On next window select Archetype as maven-archetype-quickstart. In next window accept all defaults and click Finish. Now you will see in the parent project’s (spring-microservices) pom has been updated with <modules/> tag. Now open the user-service project’s pom.xml file and remove <groupid/> and <version/> tags. Because these two values will be inherited from parent project.
  3. Now create another module email-service in the similar way as you have created user-service. Remove the <groupid/> and <version/> tags from the pom.xml file. Now again you will see the parent’s pom file has been updated to include the email-service module under <modules/> tag.

The project structure will look like similar to the below image

multi module maven project

Now you can add dependencies, plugins etc in individual children pom files as per the project requirements. You can also add common dependencies, plugins etc. in the parent project’s pom file and those dependencies will be automatically inherited in the child’s pom file. If you want to override any inherited dependency in child pom then you need to declare the same dependency in child’s pom file.

Thanks for reading.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials Twitter Facebook  Google Plus Linkedin Or Email Me

3 thoughts on “Creating Multi-Modules Maven Project in Eclipse

  1. Hi!
    Soumitra Roy Sarkar hope you are doing grate. i have a question related to this multi-modules spring boot project. see below detail
    I have 3 spring boot project.
    like A,B,C, each have rest-controller like below:-
    ——————–Project-A———————————-

    @RequestMapping(value = “/demoa”)
    public String demoa() {
    return “demoa”;
    }
    ——————–Project-B———————————-

    @RequestMapping(value = “/demob”)
    public String demob() {
    return “demob”;
    }
    ——————–Project-C———————————-

    @RequestMapping(value = “/democ”)
    public String democ() {
    return “democ”;
    }
    I add the both (B, C) project as a mavend dependency in Project(A) and compiled all

    com.b
    demob
    0.0.1-SNAPSHOT

    com.c
    democ
    0.0.1-SNAPSHOT

    after that i run my project like “mvn Spring-boot run” it run on 8080. When i call the “Rest /demoa” it give me the response while when i try to call other rest it show these error below:

    {
    “timestamp”: “2018-04-25T14:47:56.816+0000”,
    “status”: 404,
    “error”: “Not Found”,
    “message”: “No message available”,
    “path”: “/demob”
    }
    My Question is how i get the response of both 2 api while runing the proejct “A”

Leave a Reply

Your email address will not be published. Required fields are marked *