zoukankan      html  css  js  c++  java
  • 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版本,所以配置如图:

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

  • 相关阅读:
    ExtJS小技巧
    Oracle 表的行数、表占用空间大小,列的非空行数、列占用空间大小 查询
    NPM 私服
    IDEA 不编译java以外的文件
    SQL 引号中的问号在PrepareStatement 中不被看作是占位符
    Chrome 浏览器自动填表呈现淡黄色解决
    批量删除Maven 仓库未下载成功.lastupdate 的文件
    Oracle 11g 监听很慢,由于监听日志文件太大引起的问题(Windows 下)
    Hibernate 自动更新表出错 建表或添加列,提示标识符无效
    Hibernate 自动更新表出错 More than one table found in namespace
  • 原文地址:https://www.cnblogs.com/cool-fun/p/12508983.html
Copyright © 2011-2022 走看看