Parent child project dependency of Maven project in idea


1. Write in front

  • Suppose a maven project (here is an SSM integration project) and its construction layout is as follows:
    I don’t want to say much

    Parent child project dependency of Maven project in idea

  • This project has a parent-child project (the SRC folder of the parent project is deleted to make the project more readable)
  • The sub modules Dao, service and web are the MVC architecture of the project, three layers of persistence layer, business layer and view layer. Domain and utils are entity class and Toolkit respectively

2. Solve the multi root phenomenon of project module

  • The solution is given first, and then the cause of the problem is studied
    We open the parent project pom.xml Add the configuration of parent and child modules here < modules
    On the far right, we can see that the engineering structure of the project has only one root project, and the others are sub projects
    Add finished, auto configuration, OK, problem solved

    Parent child project dependency of Maven project in idea

  • As for the reason, the most likely reason is that the option of inheriting the parent project is not checked when creating a child project after creating a parent project. If this option is checked, the powerful ide of idea will automatically help you complete the construction.

3. Solve the dependency relationship between sub modules

1) Let’s talk about the packaging mode of each module

  • Let’s go on to our father’s project pom.xml The file specifies his packing method at the top. Note that the packing method is POM mode, which is used in parent project or aggregation project. Used for version control of jar package. It must be specified that the packaging method of this polymerization project is POM

Parent child project dependency of Maven project in idea

The packaging method of its sub modules is the most commonly used jar packaging method
The following four modules are all packaged in jar mode. We may notice that there is no web subproject here, because it is special, and it is not packaged with jar;
Jar package contains all the services or third-party class libraries that you write programs. It is usually a server who exchanges data processing for view layer users as a behind the scenes worker

Parent child project dependency of Maven project in idea

Web module is something that we want to deploy to tomact to provide client access. There is no complex business logic processing. A war file can be regarded as a web application. Different from jar encapsulation, it contains many pages, such as HTML, JSP, servlet, JS, CSS, icon image files, and so on. Of course, it also includes other components that make up the web application. These files basically have no complex business logic processing, and are basically only used as the portal of the program to interact with users, that’s all.

Parent child project dependency of Maven project in idea

In addition, POM packaging is POM engineering, jar packaging is jar engineering, and war packaging is war engineering. In general, it is for the separation of front and rear ends and clear structure of the project.

2) Dependency import among sub projects

  • Take the web sub project as an example. Because the operation of Dao layer and service layer is involved in this project, the import method of other modules is the same
    Parent child project dependency of Maven project in idea
  • What should be noted here is that before importing dependencies, you should first determine whether the packaging method of each module is correct, and how to package them. As mentioned above, the specific dependencies imported by each module are determined according to their own business logic

4. Finally, I will talk about a very speechless problem

In my web module, the application.xml , there have been two errors. That is, to enable annotation scanning, I always report red in these two packages. Moreover, I have imported the dependency of Dao module and service module, and still report red;
Finally, I found that the real reason is that there is no corresponding Dao module and service module pers.pluto.dao and pers.plutoservice.impl These two folders;


To sum up, I don’t have a thorough understanding of the principle of the father son project

  • The existence of the parent project is simply to establish a certain relationship between the sub projects, just as they can call each other after importing and depending on each other;
  • In fact, it has all the import dependencies, including the folder structure, such as in the Dao module pers.pluto.dao In the web project, you can use the original path directly, regardless of the path of the parent project;
  • So I directly delete the SRC folder of the parent project here to avoid misunderstanding and make the structure clearer.

Parent child project dependency of Maven project in idea