springBoot多模块,使用maven打包成jar,以此方便部署到linux

springBoot多模块,使用maven打包成jar,以此方便部署到linux

项目结构如下

meeting-parent    --父模块

meeting-base    --base模块,主要存放实体类,工具类等,是meeting-parent子模块

 <parent>
        <artifactId>meeting-parent</artifactId>
        <groupId>com.qm.meeting</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../meeting-parent/pom.xml</relativePath>
  </parent>

meeting-service-front   --服务模块,对外提供服务(对外提供api接口),真正能运行的模块

结构如下

该模块是meeting-parent子模块,同时对meeting-base模块依赖

<parent>
        <artifactId>meeting-parent</artifactId>
        <groupId>com.qm.meeting</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../meeting-parent/pom.xml</relativePath>
</parent>



<dependency>
            <groupId>com.qm.meeting</groupId>
            <artifactId>meeting-base</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
</dependency>

此时为了将meeting-service-front打包成jar,要做前提工作

将meeting-parent使用mvn install到本地仓库

将meeting-base使用mvn install到本地仓库

这样打包meeting-service-front时,就能找到meeting-base,meeting-parent

(必须先将依赖的模块install到本地仓库,否则就找不到依赖(Could not resolve dependencies for project))

为了成功将meeting-service-front打包成jar还需要在它的pom.xml文件下加入spring-boot-maven-plugin插件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.1.RELEASE</version>
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 -->
                    <mainClass>com.qm.meeting.FrontApplication</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后对meeting-service-front使用mvn clean packge,这样就能打包成功了

或者借助idea工具

打包成功后再target目录下

然后执行java -jar meeting-service-front-1.0-SNAPSHOT.jar就能运行了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值