• idea创建maven多模块开发


    创建pom父类文件,便于管理其他pom文件

    首先创建一个maven项目,口诉没有图片来的爽快,如图一步步操作

    再新建一个maven项目,创建步骤一样


    父项目zhiliao 的pom文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.example</groupId>
        <artifactId>zhiliao</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        
        <!-- 子类项目模板-->
        <modules>
            <module>zhiliao-admin</module>
            <module>zhiliao-es</module>
        </modules>
        <!-- 父包使用pom -->
        <packaging>pom</packaging>
        <!--版本号-->
        <properties>
            <java.servsion>1.8</java.servsion>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <zhiliao.version>0.0.1-SNAPSHOT</zhiliao.version>
        </properties>
    
        <!-- 依赖声明 方便项目之间调用,不可循环调用-->
        <dependencyManagement>
            <dependencies>
              <dependency>
                <groupId>com.example</groupId>
                <artifactId>zhiliao-es</artifactId>
                <version>${zhiliao.version}</version>
              </dependency>
            </dependencies>
        </dependencyManagement>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    <!--    使用阿里云maven镜像,更快下载jar包-->
        <repositories>
            <repository>
                <id>public</id>
                <name>aliyun nexus</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>
    
        <pluginRepositories>
            <pluginRepository>
                <id>public</id>
                <name>aliyun nexus</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </project>
    

    子项目pom文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <!-- 继承父类-->
        <parent>
            <artifactId>zhiliao</artifactId>
            <groupId>com.example</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
       <!-- 子包使用jar包 ,web项目可使用war包-->
        <packaging>jar</packaging>
        <artifactId>zhiliao-es</artifactId>
    
        <dependencies>
          
          
        </dependencies>
    </project>
    

    上面是多模块开发主要的pom文件,也是最基础的。

    再主模块里直接调用其他模块即可引入此模块,如下

     <!-- 引入zhiliao-es模块,需要再父pom文件声明-->
        <dependencies>
            <dependency>
                <groupId>com.example</groupId>
                <artifactId>zhiliao-es</artifactId>
            </dependency>
        </dependencies>
    

    还有两个地方需要注意application启动项中要加入@ComponentScan扫描其他模块的包,@MapperScan是扫描dao层接口

    @SpringBootApplication
    @MapperScan("com.example.demo.dao")
    @ComponentScan("com.example.search")
    public class DemoApplication {
    	public static void main(String[] args) {
    		SpringApplication.run(DemoApplication.class, args);
    	}
    
    }
    

    最后jdk语言版本需要统一,我使用的是1.8版本,所以配置如图:

    以上便是创建多模块注意的点,亲自踏坑,希望对你有所帮助!

  • 相关阅读:
    YOLOv5实现自定义对象训练与OpenVINO部署全解析
    GMS程序调试指南GMS-Feature-Matcher
    MobileNet V3与Lite R-ASPP 总结
    codevs 3385 拯救Oier(一) Save Oier—first
    喵哈哈村的魔法考试 Round #6 (Div.3) 题解
    POJ 1852 Ants
    加强赛第一轮题解
    喵哈哈村的魔法考试 Round #3 (Div.2)
    python小数据池,代码块的最详细、深入剖析
    比较三个数的大小
  • 原文地址:https://www.cnblogs.com/cool-fun/p/12508983.html
Copyright © 2020-2023  润新知