Spring Boot多模块项目打包

这篇具有很好参考价值的文章主要介绍了Spring Boot多模块项目打包。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Spring Boot多模块项目打包

例如父项目 build_test 下面有三个子模块,一个是common模块 一个是a模块,一个b模块;其中common是公共模块,a和b都依赖于公共模块common,我现在想把a和b模块打包成jar包。

创建项目

创建父工程

Spring Boot多模块项目打包

Spring Boot多模块项目打包

创建3个子模块,分别是common和a和b模块

鼠标右击红框位置
Spring Boot多模块项目打包
Spring Boot多模块项目打包

选New 再选Module,鼠标左键点一下,
Spring Boot多模块项目打包
Spring Boot多模块项目打包

Spring Boot多模块项目打包

Spring Boot多模块项目打包

同理创建出后面两个模块,最后删除父工程的src目录
Spring Boot多模块项目打包
Spring Boot多模块项目打包

项目创建成功

添加项目依赖

build_test 父工程的pom.xml

<?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.hongchun</groupId>
    <artifactId>build_test</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>common</module>
        <module>a</module>
        <module>b</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <!-- SpringBoot的依赖配置-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.3.12.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--mybatisPlus依赖-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.3</version>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <build>
        <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>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>

                    <skipTests>true</skipTests>  <!--默认关掉单元测试 -->

                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

主要是build部分 还有上面要打包成pom包

    <build>
        <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>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>

                    <skipTests>true</skipTests>  <!--默认关掉单元测试 -->

                </configuration>
            </plugin>
        </plugins>
    </build>
<packaging>pom</packaging>

common模块的pom.xml

<?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>build_test</artifactId>
        <groupId>com.hongchun</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>common</artifactId>
    <packaging>jar</packaging>
    <dependencies>
        <!--spring boot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--mybatisPlus依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
        <!--mysql数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

</project>

common模块这里不是启动模块,不需要加build,也是打包成jar包

a模块的pom.xml

<?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>build_test</artifactId>
        <groupId>com.hongchun</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>a</artifactId>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>com.hongchun</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <!--重要,一定要配置,不然会出现找不到清单文件-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.hongchun.AApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这里build一定要配置,com.hongchun.AApplication换成你的启动类

b模块的pom.xml

<?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>build_test</artifactId>
        <groupId>com.hongchun</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>b</artifactId>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>com.hongchun</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.hongchun.BApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

也是打包成jar,和a模块一样,只是启动类不同

开始打包

Spring Boot多模块项目打包

一定要选择带root的,先clean,再package.
Spring Boot多模块项目打包

找到a和b模块的jar包,然后测试启动

测试

找到jar包所在目录,打开doc窗口,输入java -jar a-1.0-SNAPSHOT.jar
Spring Boot多模块项目打包

再把b模块的jar包启动
Spring Boot多模块项目打包

使用postman测试接口

1.a模块的localhost:8000/a/list

Spring Boot多模块项目打包

2.b模块的localhost:9000/b/list

Spring Boot多模块项目打包

本次测试的源代码如下

阿里云盘地址: https://www.aliyundrive.com/s/EdFuAwfqoFE

百度网盘地址:链接:https://pan.baidu.com/s/14P48B2bnF3OosB9mynZzgA
提取码:midp文章来源地址https://www.toymoban.com/news/detail-492347.html

到了这里,关于Spring Boot多模块项目打包的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • java 配置打包Spring Boot项目过程中跳过测试环节

    上文 java 打包Spring Boot项目,并运行在windows系统中中 我们演示了打包 Spring Boot项目的并运行在本地的方法 但是 我们这里会看到 每次打包 他这都会有个T E S T S 测试的部分 但是 我们自己开发的程序 要上线 有没有问题我们肯定自己清楚啊 没必要它做测试 而且有些程序走这个

    2024年02月13日
    浏览(34)
  • 将Spring Boot项目打包部署到阿里云linux服务器

    首先 你要保证自己的服务器上有java环境 如果没有可以参考我的文章 linux服务器中安装java JDK1.8版本 然后 我们打开我们的Spring Boot项目 双击 package 生命周期进行打包 打包完成之后 我们找到 target 下面会有一个jar包 然后 我们右键它 如下图操作 系统就会帮你打开它所在的目录

    2024年02月16日
    浏览(45)
  • Spring Boot多模块项目的创建和配置(Maven工程多模块)

    在进行分布式系统开发时,我们通常会创建多个模块的工程项目。即每一个功能就是一个Spring Boot工程,作为一个个模块,然后这些模块都会有一个父模块,父模块通常没有代码只有一个 pom.xml 。 今天就来分享一下Spring Boot如何创建一个多模块项目,以创建一个两个子模块的

    2024年02月12日
    浏览(29)
  • 工程项目管理系统源码+功能清单+项目模块+spring cloud +spring boot em

    ​   工程项目管理软件(工程项目管理系统)对建设工程项目管理组织建设、项目策划决策、规划设计、施工建设到竣工交付、总结评估、运维运营,全过程、全方位的对项目进行综合管理    工程项目各模块及其功能点清单 一、系统管理     1、数据字典:实现对数据字典

    2024年02月12日
    浏览(40)
  • spring boot3单模块项目工程搭建-上(个人开发模板)

      ⛰️个人主页:     蒾酒 🔥系列专栏 :《spring boot实战》 目录 写在前面 上文衔接 常规目录创建 common目录 exception.handle目录 result.handle目录 controller目录 service目录 mapper目录 entity目录 test目录 写在最后 本文介绍了springboot开发后端服务,单模块项目工程搭建。单模块搭建出

    2024年04月29日
    浏览(27)
  • spring boot3单模块项目工程搭建-下(个人开发模板)

    ⛰️个人主页:     蒾酒 🔥系列专栏 :《spring boot实战》 目录 写在前面 上文衔接 常用依赖介绍以及整合 web组件 测试组件 样板代码生成 数据库连接器 常用工具包 面向切面编程 ORM框架 数据连接池 接口测试、文档导出 缓存中间件 参数校验 认证鉴权 基础功能完善 跨域问

    2024年04月28日
    浏览(30)
  • 网页版Java(Spring/Spring Boot/Spring MVC)五子棋项目(四)对战模块

    匹配成功返回数据 1. message消息类别 2. ok 3. reson 4. 房间id 5. 双方id 6.白色玩家 一个类记录房间中的信息(房间id,两个用户id,是否为白棋) 信息提示框 处理匹配API 初始化游戏(棋盘,下一个棋子,接受棋子处理响应,判断是否结束) 1. 客户端连接到游戏房间后, 服务器返回

    2024年02月13日
    浏览(38)
  • Java版企业工程项目管理系统源码+java版本+项目模块功能清单+spring cloud +spring boot

          工程项目各模块及其功能点清单 一、系统管理     1、数据字典:实现对数据字典标签的增删改查操作     2、编码管理:实现对系统编码的增删改查操作     3、用户管理:管理和查看用户角色     4、菜单管理:实现对系统菜单的增删改查操作     5、角色管理:

    2024年02月16日
    浏览(35)
  • 解决Spring Boot项目中pom.xml环境配置 打包后生效 但idea版本运行无效的问题

    上文 Spring Boot中通过maven进行多环境配置 中我们通过pom.xml配置了环境选择 但这个只有在打包出来的jar中生效 我们直接通过 idea启动 这个东西确实是有点问题 其实 我们执行一下 compile 手工编译一下 然后重新启动 很明显 我们这里配置就已经生效了 这个就是 我们每次改pom.x

    2024年02月10日
    浏览(40)
  • IDEA 中搭建 Spring Boot Maven 多模块项目 (父SpringBoot+子Maven)

    [Ref] 新建一个SpringBoot项目 删除无用的 .mvn 目录、 src 目录、 mvnw 及 mvnw.cmd 文件,最终只留 .gitignore 和 pom.xml ① 删除 dependencies 标签及其中的 spring-boot-starter 和 spring-boot-starter-test 依赖,因为 Spring Boot 提供的父工程已包含,并且父 pom 原则上都是通过 dependencyManagement 标签管理

    2024年01月20日
    浏览(61)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包