Create multi project Maven (multi module aggregation project, including java common project and web multi project) in IntelliJ IDEA

Posted by jwbworks on Sun, 13 Feb 2022 03:11:14 +0100

catalogue

1. Common java multi project

1.1 create parent project

1.2 creating subprojects

1.2.1 create subproject children1

1.2.2 create subproject children2 and use subproject children1

1.2.3 create subproject children3 and use subproject children2

1.2.4 adding project files

1.2.5 operation items

2. web multi project

2.1 create parent project

2.2 creating subprojects

2.2.1 create subproject children1

2.2.2 create subproject children2 and use subproject children1

2.2.3 create subproject children3 and use subproject children2

2.2.4 configure the subproject children3 as a web project

I created it according to the online tutorial before, and now I forget / (ㄒ o ㄒ) / ~ ~, so now record the creation process and record it again!!!

1. Common java multi project

1.1 create parent project

  

1.2 creating subprojects

1.2.1 create subproject children1

1.2.2 create subproject children2 and use subproject children1

Continue to add a children2 to the parent according to the creation method of children1

1.2.3 create subproject children3 and use subproject children2

Continue to add a children3 to the parent according to the creation method of children2

1.2.4 adding project files

I'm going to have children2 call children1 and children3 call children2.

Add files to children1 first:

package com.vae.child1;

/**
 * description: com.vae.child1.Children01 <br>
 * date: 2022/1/11 22:11 <br>
 * author: vae <br>
 * version: 1.0 <br>
 */
public class Children01 {
    public void children01(){
        System.out.println("--------------------children01--------------------");
    }
}

Then add the calling file and calling method to children2

package com.vae.child2;

import com.vae.child1.Children01;

/**
 * description: com.vae.child1.Children01 <br>
 * date: 2022/1/11 22:11 <br>
 * author: vae <br>
 * version: 1.0 <br>
 */
public class Children02 {

    public void children02(){
        Children01 children01 = new Children01();
        children01.children01();
        System.out.println("--------------------children02--------------------");
    }
}

An error is reported here because we need to rely on children1's project to children2 so that children2 can access and use it. We need to add dependencies to children2's pom file:

<dependencies>
        <dependency>
            <groupId>com.vae.demo01.children1</groupId>
            <artifactId>children1</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

    </dependencies>

Note: if you still report an error, you need to refresh the Maven Project. Click the refresh button in the Maven Project on the right side of the idea to refresh:

Now we find that there is no error. We continue to add files and methods to children3. Here we add the main method:

package com.vae.child3;


import com.vae.child1.Children01;
import com.vae.child2.Children02;

/**
 * description: com.vae.child1.Children01 <br>
 * date: 2022/1/11 22:11 <br>
 * author: vae <br>
 * version: 1.0 <br>
 */
public class Children03 {

    public static void main(String[] args) {
        Children02 children02 = new Children02();
        children02.children02();
        System.out.println("--------------------children03--------------------");
    }
}

Similarly, you need to add the dependency of children2 to children3:

    <dependencies>
        <dependency>
            <groupId>com.vae.demo01.children2</groupId>
            <artifactId>children2</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

    </dependencies>

1.2.5 operation items

Run the main method of children3 and the discovery is successful!

What we saw above is the multi project aggregation implementation of common java projects. In fact, it is the same for web multi projects, that is, there are a little more things to configure, and the whole process is roughly the same.

Now we change children3 into a web project, and children2 and children1 are still ordinary projects:

children1: entity class, dao interface

children2: service class and interface

children3: controller class, so it needs to be modified as a web project.

2. web multi project

2.1 create parent project

Ibid

2.2 creating subprojects

Ibid

2.2.1 create subproject children1

Ibid

2.2.2 create subproject children2 and use subproject children1

Ibid

2.2.3 create subproject children3 and use subproject children2

Ibid

2.2.4 configure the subproject children3 as a web project

First add the following folders and files to children3:

Then

First select children3, then click the + sign in the upper left corner and select web, as follows:

 

Topics: Java Back-end intellij-idea