打开IDEA

IntelliJ IDEA构建多Module项目

 

 

 

 

 IntelliJ IDEA构建多Module项目

 

 

IntelliJ IDEA构建多Module项目

 

 

IntelliJ IDEA构建多Module项目

 

 

IntelliJ IDEA构建多Module项目

 

 

 

创建完成项目后,我们创建子模块

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

可以看到common子模块创建成功,子模块的名字大家可以根据自己的实际需求来修改

 

下面我们再创建子模块

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

给子模块起个名字

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

现在已经创建好多模块的项目了,下一步设置模块之间的依赖关系

IntelliJ IDEA构建多Module项目

 

 

 

 

我们来设定behavior模块依赖也common模块

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

IntelliJ IDEA构建多Module项目

 

 

 

在behavior的pom文件里面添加common模块的依赖

IntelliJ IDEA构建多Module项目

 <dependencies>
        <dependency>
            <groupId>com.gongmod</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

 

 

依赖关系设置好后,我们进行代码的调用

在common模块新建包

 IntelliJ IDEA构建多Module项目

 

 

 IntelliJ IDEA构建多Module项目

 

 

 

创建一个类

IntelliJ IDEA构建多Module项目

 

 

IntelliJ IDEA构建多Module项目

 

IntelliJ IDEA构建多Module项目

 

 

package com.gong;

public class Dome1 {
    public void Test(){
        System.out.println("第一个测试方法");
    }
}

 

 

 

在behavior子模块创建包

IntelliJ IDEA构建多Module项目

 

 

 

新建一个类

IntelliJ IDEA构建多Module项目

 

 IntelliJ IDEA构建多Module项目

 

 

package com.gong;

public class Demo2 {
    public static void main(String[] args) {
        Dome1 dome1=new Dome1();
        dome1.Test();
    }
}

 

 

运行程序

IntelliJ IDEA构建多Module项目

 

相关文章: