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就能运行了