java基于maven多模块合并打包部署的操作过程
项目环境
- jdk 1.8
- spring 2.7.x
- Maven 3.6
项目结构
模块功能
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配置项等
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目录
生成的main jar,及包含了所有模块
到此这篇关于java 基于maven多模块合并打包部署的文章就介绍到这了,更多相关maven多模块合并打包部署内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
相关文章