温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java基于maven多模块合并打包部署的方法是什么

发布时间:2023-02-24 10:09:07 来源:亿速云 阅读:85 作者:iii 栏目:开发技术

这篇文章主要介绍“java基于maven多模块合并打包部署的方法是什么”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“java基于maven多模块合并打包部署的方法是什么”文章能帮助大家解决问题。

项目环境

  • jdk 1.8

  • spring 2.7.x

  • maven 3.6

项目结构

java基于maven多模块合并打包部署的方法是什么

模块功能

client – 对外service
common – 共用工具切面等
main – 启动类
goods – 子模块具体实现

模块间依赖关系

client – 无依赖
common – 无依赖
main – client、common、goods
goods – client、common

具体POM配置

顶级pom

引入需要被使用的所有项目子模块,并统一制定版本号

    <groupId>org.ct</groupId>
    <artifactId>gp-data-analysis</artifactId>
    <packaging>pom</packaging>
    <version>${gp-data.version}</version>
    <modules>
        <module>gp-data-client</module>
        <module>gp-data-common</module>
        <module>gp-futrue-goods</module>
        <module>gp-data-main</module>
    </modules>
    
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <gp-data.version>1.0.0</gp-data.version>
    </properties>

	<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-analysis</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-main</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-common</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-client</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-futrue</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
         </dependencies>
    </dependencyManagement>

	<build>
		<!-- 引入maven打包工具 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

client、common、goods类似

	<!-- 指定父pom版本 -->
    <parent>
        <artifactId>gp-data-analysis</artifactId>
        <groupId>org.ct</groupId>
        <version>${gp-data.version}</version>
    </parent>

main 设置打包入口,扫描的xml配置项等
&emsp; &emsp; main 中dependency中引入顺序需要注意,需要保证,未被依赖的在前,被依赖的子模块在后。因为此处的顺序决定了maven install的顺序

    <parent>
        <artifactId>gp-data-analysis</artifactId>
        <groupId>org.ct</groupId>
        <version>${gp-data.version}</version>
    </parent>
     <dependencies>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-common</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-futrue</artifactId>
        </dependency>
    </dependencies>

	 <build>
        <plugins>
            <!--打包插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <goals>
                            <!-- 整合打jar包 -->
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--支持静态文件热部署-->
                    <addResources>true</addResources>
                    <!-- 指定该Main Class为全局的唯一入口 -->
                    <mainClass>org.ct.gp.GpDataBootApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>

        <!--打包规则,打包时将resources文件夹打包进去-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>

            <!--保证mapper文件夹中的.xml文件可以被编译-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

使用maven打包root目录

java基于maven多模块合并打包部署的方法是什么

生成的main jar,及包含了所有模块

java基于maven多模块合并打包部署的方法是什么

关于“java基于maven多模块合并打包部署的方法是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI