gitee地址:ruoyi-pom-config: 用来修改ruoyi-cloud的pom文件示例,第三方jar包抽取打包
以若依微服务项目为说明示例,需要用git下载下来结合理解,后端项目结构
图一:
红圈一的pom为最父级的pom文件
最父级 pom文件内容如下
<?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.ruoyi</groupId> <artifactId>ruoyi</artifactId> <version>3.6.3</version> <name>ruoyi</name> <url>http://www.ruoyi.vip</url> <description>若依微服务系统</description> <properties> <ruoyi.version>3.6.3</ruoyi.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-boot.version>2.7.13</spring-boot.version> <spring-cloud.version>2021.0.8</spring-cloud.version> <spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version> <spring-boot-admin.version>2.7.10</spring-boot-admin.version> <swagger.fox.version>3.0.0</swagger.fox.version> <swagger.core.version>1.6.2</swagger.core.version> <tobato.version>1.27.2</tobato.version> <kaptcha.version>2.3.3</kaptcha.version> <pagehelper.boot.version>1.4.7</pagehelper.boot.version> <druid.version>1.2.16</druid.version> <dynamic-ds.version>3.5.2</dynamic-ds.version> <commons.io.version>2.13.0</commons.io.version> <velocity.version>2.3</velocity.version> <fastjson.version>2.0.39</fastjson.version> <jjwt.version>0.9.1</jjwt.version> <minio.version>8.2.2</minio.version> <poi.version>4.1.2</poi.version> <transmittable-thread-local.version>2.14.3</transmittable-thread-local.version> </properties> <!-- 依赖声明 --> <dependencyManagement> <dependencies> <!-- SpringCloud 微服务 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- SpringCloud Alibaba 微服务 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- SpringBoot 依赖配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- FastDFS 分布式文件系统 --> <dependency> <groupId>com.github.tobato</groupId> <artifactId>fastdfs-client</artifactId> <version>${tobato.version}</version> </dependency> <!-- Swagger 依赖配置 --> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>${swagger.core.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>${swagger.core.version}</version> </dependency> <!-- 验证码 --> <dependency> <groupId>pro.fessional</groupId> <artifactId>kaptcha</artifactId> <version>${kaptcha.version}</version> </dependency> <!-- pagehelper 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>${pagehelper.boot.version}</version> </dependency> <!-- io常用工具类 --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons.io.version}</version> </dependency> <!-- excel工具 --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}</version> </dependency> <!-- 代码生成使用模板 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>${velocity.version}</version> </dependency> <!-- JSON 解析器和生成器 --> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>${fastjson.version}</version> </dependency> <!-- JWT --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jjwt.version}</version> </dependency> <!-- 线程传递值 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>transmittable-thread-local</artifactId> <version>${transmittable-thread-local.version}</version> </dependency> <!-- 核心模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-core</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 接口模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 安全模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-security</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 权限范围 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datascope</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 多数据源 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datasource</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 分布式事务 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-seata</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 日志记录 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-log</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 缓存服务 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-redis</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 系统接口 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-system</artifactId> <version>${ruoyi.version}</version> </dependency> </dependencies> </dependencyManagement> <modules> <module>ruoyi-auth</module> <module>ruoyi-gateway</module> <module>ruoyi-visual</module> <module>ruoyi-modules</module> <module>ruoyi-api</module> <module>ruoyi-common</module> </modules> <packaging>pom</packaging> <dependencies> <!-- bootstrap 启动器 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <!--打包到D盘根目录--> <configuration> <outputDirectory>D:\</outputDirectory> </configuration> </plugin> </plugins> </pluginManagement> </build> <repositories> <repository> <id>public</id> <name>aliyun nexus</name> <url>https://maven.aliyun.com/repository/public</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>aliyun nexus</name> <url>https://maven.aliyun.com/repository/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
先重点看最父级pom文件,下面图中的红圈部分
图二:
红圈二是所有子模块中有启动类的,需要打包成可执行jar包的,对其pom中spring-boot-maven-plugin版本的统一管理,ruoyi-gateway,ruoyi-auth,ruoyi-visual以及ruoyi-modules聚合模块下的所有子模块
图三:
这些子模块的pom中都有如下图所示部分
图四:
因为它们都有启动类,都会被打包成可执行的jar包 ,其他诸如ruoyi-common模块下的子模块
图五:
ruoyi-api下的子模块
图六:
这些子模块的pom中没有图四部分,这些pom中也没有<packaging>pom</packaging>
只有聚合模块,就是有子模块的如ruoyi-api,ruoyi-common,ruoyi-modules,RuoYi-Cloud这些文件夹根目录下都会有一个聚合其子模块的pom文件
包含<packaging>pom</packaging>,帮助子模块打包构建的,同时父工程中导入的其他依赖,子模块也可享有
图七:
如果pom文件中没有<packaging>pom</packaging>,也没有<packaging>war</packaging>(打成war包,需要放到web容器如tomcat中才能运行),
如ruoyi-common,ruoyi-api下的所有子模块的pom,则默认会打成jar包,但是这些子模块pom中也没有图四部分,所有这些模块打的jar包只是普通的jar包,就像我们引入的其他第三方依赖的jar一样,这些普通jar是无法通过java -jar xxx.jar运行的,因为,没有使用spring-boot-maven-plugin,也没有启动类
红圈一说明:
只有最父级的聚合pom文件有此部分,其他下属子模块中,属于聚合模块的pom,即有<packaging>pom</packaging>的,既没有maven-compiler-plugin 也没有spring-boot-maven-plugin,不属于聚合模块,且有启动类需要打包可执行jar的有spring-boot-maven-plugin,即图四部分,不属于聚合模块,且没有启动类的,既没有maven-compiler-plugin 也没有spring-boot-maven-plugin
maven-compiler-plugin 与spring-boot-maven-plugin 区别如下:
从图二中可以看到最父级的pom使用的是 maven-compiler-plugin
这个是maven用来编译管理所有可执行的jar依赖包的,放入一个仓库,方便管理
最父级pom这里,加上这个,即可把所有可执行jar包打包到指定文件夹下
抽离第三方jar方式,最父级pom添加
<?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.ruoyi</groupId> <artifactId>ruoyi</artifactId> <version>3.6.3</version> <name>ruoyi</name> <url>http://www.ruoyi.vip</url> <description>若依微服务系统</description> <properties> <ruoyi.version>3.6.3</ruoyi.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-boot.version>2.7.13</spring-boot.version> <spring-cloud.version>2021.0.8</spring-cloud.version> <spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version> <spring-boot-admin.version>2.7.10</spring-boot-admin.version> <swagger.fox.version>3.0.0</swagger.fox.version> <swagger.core.version>1.6.2</swagger.core.version> <tobato.version>1.27.2</tobato.version> <kaptcha.version>2.3.3</kaptcha.version> <pagehelper.boot.version>1.4.7</pagehelper.boot.version> <druid.version>1.2.16</druid.version> <dynamic-ds.version>3.5.2</dynamic-ds.version> <commons.io.version>2.13.0</commons.io.version> <velocity.version>2.3</velocity.version> <fastjson.version>2.0.39</fastjson.version> <jjwt.version>0.9.1</jjwt.version> <minio.version>8.2.2</minio.version> <poi.version>4.1.2</poi.version> <transmittable-thread-local.version>2.14.3</transmittable-thread-local.version> </properties> <!-- 依赖声明 --> <dependencyManagement> <dependencies> <!-- SpringCloud 微服务 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- SpringCloud Alibaba 微服务 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- SpringBoot 依赖配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- FastDFS 分布式文件系统 --> <dependency> <groupId>com.github.tobato</groupId> <artifactId>fastdfs-client</artifactId> <version>${tobato.version}</version> </dependency> <!-- Swagger 依赖配置 --> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>${swagger.core.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>${swagger.core.version}</version> </dependency> <!-- 验证码 --> <dependency> <groupId>pro.fessional</groupId> <artifactId>kaptcha</artifactId> <version>${kaptcha.version}</version> </dependency> <!-- pagehelper 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>${pagehelper.boot.version}</version> </dependency> <!-- io常用工具类 --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons.io.version}</version> </dependency> <!-- excel工具 --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}</version> </dependency> <!-- 代码生成使用模板 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>${velocity.version}</version> </dependency> <!-- JSON 解析器和生成器 --> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>${fastjson.version}</version> </dependency> <!-- JWT --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jjwt.version}</version> </dependency> <!-- 线程传递值 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>transmittable-thread-local</artifactId> <version>${transmittable-thread-local.version}</version> </dependency> <!-- 核心模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-core</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 接口模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 安全模块 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-security</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 权限范围 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datascope</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 多数据源 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datasource</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 分布式事务 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-seata</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 日志记录 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-log</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 缓存服务 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-redis</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- 系统接口 --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-system</artifactId> <version>${ruoyi.version}</version> </dependency> </dependencies> </dependencyManagement> <modules> <module>ruoyi-auth</module> <module>ruoyi-gateway</module> <module>ruoyi-visual</module> <module>ruoyi-modules</module> <module>ruoyi-api</module> <module>ruoyi-common</module> </modules> <packaging>pom</packaging> <dependencies> <!-- bootstrap 启动器 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <!--指定所有可执行jar包的打包路径--> <configuration> <outputDirectory>D:\</outputDirectory> </configuration> </plugin> <!--抽离第三方依赖jar相关管理--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.6.0</version> </plugin> </plugins> </pluginManagement> </build> <repositories> <repository> <id>public</id> <name>aliyun nexus</name> <url>https://maven.aliyun.com/repository/public</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>aliyun nexus</name> <url>https://maven.aliyun.com/repository/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
其他需要打成可执行jar的pom修改如下
ruoyi-auth :
<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> <groupId>com.ruoyi</groupId> <artifactId>ruoyi</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-auth</artifactId> <description> ruoyi-auth认证授权中心 </description> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- RuoYi Common Security--> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-security</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <!--打包时去除第三方依赖--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <!--实际应用中可以不考虑项目自身依赖排除问题,统一全部拷贝的lib下,这里只是为了练习才include--> <includes> <!-- 不排除的依赖,依赖的项目自身依赖,不去除,从上面找--> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-common-security</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-api-system</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-common-core</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-common-redis</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <!-- 不拷贝的依赖,也是项目自身依赖,非第三方 --> <!--实际应用中可以不考虑项目自身依赖不拷贝问题,统一全部拷贝的lib下,这里只是为了练习才exclude--> <excludeArtifactIds> ${project.parent.artifactId}-common-security, ${project.parent.artifactId}-api-system, ${project.parent.artifactId}-common-core, ${project.parent.artifactId}-common-redis </excludeArtifactIds> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi-gateway:
<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> <groupId>com.ruoyi</groupId> <artifactId>ruoyi</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-gateway</artifactId> <description> ruoyi-gateway网关模块 </description> <dependencies> <!-- SpringCloud Gateway --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel Gateway --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId> </dependency> <!-- Sentinel Datasource Nacos --> <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-datasource-nacos</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- SpringCloud Loadbalancer --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency> <!--验证码 --> <dependency> <groupId>pro.fessional</groupId> <artifactId>kaptcha</artifactId> </dependency> <!-- RuoYi Common Redis--> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-redis</artifactId> </dependency> <!-- Swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.fox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.fox.version}</version> </dependency> </dependencies> <!--加了此配置,打包成可执行的jar包(即可以通过 java -jar ruoyi-gateway.jar命令运行)--> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!-- 不排除的依赖,依赖的项目自身依赖,不去除,从上面RuoYi Common Redis找,一级一级找,凡是<groupId>com.ruoyi</groupId>,都需要排除--> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-common-core</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>${project.parent.artifactId}-common-redis</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <!-- 不拷贝的依赖,也是项目自身依赖,非第三方 --> <excludeArtifactIds> ${project.parent.artifactId}-common-core, ${project.parent.artifactId}-common-redis </excludeArtifactIds> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi- monitor:
<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> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-visual</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-visual-monitor</artifactId> <description> ruoyi-visual-monitor监控中心 </description> <dependencies> <!-- SpringBoot Admin --> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Security --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!--这个要加一个,不加不行--> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <excludeArtifactIds/> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi-file:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-modules</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-modules-file</artifactId> <description> ruoyi-modules-file文件服务 </description> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- FastDFS --> <dependency> <groupId>com.github.tobato</groupId> <artifactId>fastdfs-client</artifactId> </dependency> <!-- Minio --> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>${minio.version}</version> </dependency> <!-- RuoYi Api System --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-system</artifactId> </dependency> <!-- RuoYi Common Swagger --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!-- 不排除的依赖,依赖的项目自身依赖,不去除,从上面RuoYi Common Redis找,一级一级找,凡是<groupId>com.ruoyi</groupId>,都需要排除--> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>ruoyi-api-system</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>ruoyi-common-redis</artifactId> </include> <include> <groupId>${project.parent.groupId}</groupId> <artifactId>ruoyi-common-swagger</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <!-- 不拷贝的依赖,也是项目自身依赖,非第三方 --> <excludeArtifactIds> ruoyi-api-system, ruoyi-common-core, ruoyi-common-swagger </excludeArtifactIds> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi-gen:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-modules</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-modules-gen</artifactId> <description> ruoyi-modules-gen代码生成 </description> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- Swagger UI --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.fox.version}</version> </dependency> <!-- Apache Velocity --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> </dependency> <!-- Mysql Connector --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> </dependency> <!-- RuoYi Common Log --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-log</artifactId> </dependency> <!-- RuoYi Common Swagger --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!--这里要加一个,不加不行,不加抽离第三方jar失败--> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <excludeArtifactIds/> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi-job:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-modules</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-modules-job</artifactId> <description> ruoyi-modules-job定时任务 </description> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- Swagger UI --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.fox.version}</version> </dependency> <!-- Quartz --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <exclusions> <exclusion> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> </exclusion> </exclusions> </dependency> <!-- Mysql Connector --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> </dependency> <!-- RuoYi Common Log --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-log</artifactId> </dependency> <!-- RuoYi Common Swagger --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!--这里要加一个,不加不行,不加抽离第三方jar失败--> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <excludeArtifactIds/> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
ruoyi-system:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-modules</artifactId> <version>3.6.3</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ruoyi-modules-system</artifactId> <description> ruoyi-modules-system系统模块 </description> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- Swagger UI --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.fox.version}</version> </dependency> <!-- Mysql Connector --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> </dependency> <!-- RuoYi Common DataSource --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datasource</artifactId> </dependency> <!-- RuoYi Common DataScope --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-datascope</artifactId> </dependency> <!-- RuoYi Common Log --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-log</artifactId> </dependency> <!-- RuoYi Common Swagger --> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common-swagger</artifactId> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <fork>true</fork> <layout>ZIP</layout> <includes> <!--这里要加一个,不加不行,不加抽离第三方jar失败--> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> </plugin> <!--拷贝第三方依赖文件到指定目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依赖jar包的输出目录,根据自己喜好配置--> <outputDirectory>D:\ruoyi-lib\${project.artifactId}-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> <excludeArtifactIds/> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
我这里测试了下放到D盘,抽离后的打包结果如下:
可以看到抽离第三方jar包后,项目自身包明显小了很多
假如在linux中把ruoyi-lib和打包的自身jar方法home文件夹下
linux运行项目的jar包就不是之前的: nohup java -jar xxx.jar & 了
需要指定lib目录: nohup java -Dloader.path=lib包的路径,resources,lib -Dfile.encoding=utf-8 -jar xxx.jar &文章来源:https://www.toymoban.com/news/detail-830852.html
例如 nohup java -Dloader.path=/home/ruoyi-lib/ruoyi-gateway-lib,resources,lib -Dfile.encoding=utf-8 -jar ruoyi-gateway.jar &文章来源地址https://www.toymoban.com/news/detail-830852.html
到了这里,关于maven打包抽离第三方jar的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!