gitee地址:ruoyi-pom-config: 用来修改ruoyi-cloud的pom文件示例,第三方jar包抽取打包

以若依微服务项目为说明示例,需要用git下载下来结合理解,后端项目结构

图一:

红圈一的pom为最父级的pom文件

最父级pom文件内容如下

4.0.0com.ruoyiruoyi3.6.3ruoyihttp://www.ruoyi.vip若依微服务系统3.6.3UTF-8UTF-81.82.7.132021.0.82021.0.5.02.7.103.0.01.6.21.27.22.3.31.4.71.2.163.5.22.13.02.32.0.390.9.18.2.24.1.22.14.3org.springframework.cloudspring-cloud-dependencies${spring-cloud.version}pomimportcom.alibaba.cloudspring-cloud-alibaba-dependencies${spring-cloud-alibaba.version}pomimportorg.springframework.bootspring-boot-dependencies${spring-boot.version}pomimportcom.github.tobatofastdfs-client${tobato.version}io.swaggerswagger-models${swagger.core.version}io.swaggerswagger-annotations${swagger.core.version}pro.fessionalkaptcha${kaptcha.version}com.github.pagehelperpagehelper-spring-boot-starter${pagehelper.boot.version}commons-iocommons-io${commons.io.version}org.apache.poipoi-ooxml${poi.version}org.apache.velocityvelocity-engine-core${velocity.version}com.alibaba.fastjson2fastjson2${fastjson.version}io.jsonwebtokenjjwt${jjwt.version}com.alibabatransmittable-thread-local${transmittable-thread-local.version}com.ruoyiruoyi-common-core${ruoyi.version}com.ruoyiruoyi-common-swagger${ruoyi.version}com.ruoyiruoyi-common-security${ruoyi.version}com.ruoyiruoyi-common-datascope${ruoyi.version}com.ruoyiruoyi-common-datasource${ruoyi.version}com.ruoyiruoyi-common-seata${ruoyi.version}com.ruoyiruoyi-common-log${ruoyi.version}com.ruoyiruoyi-common-redis${ruoyi.version}com.ruoyiruoyi-api-system${ruoyi.version}ruoyi-authruoyi-gatewayruoyi-visualruoyi-modulesruoyi-apiruoyi-commonpomorg.springframework.cloudspring-cloud-starter-bootstraporg.apache.maven.pluginsmaven-compiler-plugin3.11.0${java.version}${java.version}${project.build.sourceEncoding}org.springframework.bootspring-boot-maven-plugin${spring-boot.version}repackageD:\publicaliyun nexushttps://maven.aliyun.com/repository/publictruepublicaliyun nexushttps://maven.aliyun.com/repository/publictruefalse

先重点看最父级pom文件,下面图中的红圈部分

图二:

红圈二是所有子模块中有启动类的,需要打包成可执行jar包的,对其pom中spring-boot-maven-plugin版本的统一管理,ruoyi-gateway,ruoyi-auth,ruoyi-visual以及ruoyi-modules聚合模块下的所有子模块

图三:

这些子模块的pom中都有如下图所示部分

图四:

因为它们都有启动类,都会被打包成可执行的jar包 ,其他诸如ruoyi-common模块下的子模块

图五:

ruoyi-api下的子模块

图六:

这些子模块的pom中没有图四部分,这些pom中也没有pom

只有聚合模块,就是有子模块的如ruoyi-api,ruoyi-common,ruoyi-modules,RuoYi-Cloud这些文件夹根目录下都会有一个聚合其子模块的pom文件

包含pom,帮助子模块打包构建的,同时父工程中导入的其他依赖,子模块也可享有

图七:

如果pom文件中没有pom,也没有war(打成war包,需要放到web容器如tomcat中才能运行),

如ruoyi-common,ruoyi-api下的所有子模块的pom,则默认会打成jar包,但是这些子模块pom中也没有图四部分,所有这些模块打的jar包只是普通的jar包,就像我们引入的其他第三方依赖的jar一样,这些普通jar是无法通过java -jar xxx.jar运行的,因为,没有使用spring-boot-maven-plugin,也没有启动类

红圈一说明:

只有最父级的聚合pom文件有此部分,其他下属子模块中,属于聚合模块的pom,即有pom的,既没有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添加

4.0.0com.ruoyiruoyi3.6.3ruoyihttp://www.ruoyi.vip若依微服务系统3.6.3UTF-8UTF-81.82.7.132021.0.82021.0.5.02.7.103.0.01.6.21.27.22.3.31.4.71.2.163.5.22.13.02.32.0.390.9.18.2.24.1.22.14.3org.springframework.cloudspring-cloud-dependencies${spring-cloud.version}pomimportcom.alibaba.cloudspring-cloud-alibaba-dependencies${spring-cloud-alibaba.version}pomimportorg.springframework.bootspring-boot-dependencies${spring-boot.version}pomimportcom.github.tobatofastdfs-client${tobato.version}io.swaggerswagger-models${swagger.core.version}io.swaggerswagger-annotations${swagger.core.version}pro.fessionalkaptcha${kaptcha.version}com.github.pagehelperpagehelper-spring-boot-starter${pagehelper.boot.version}commons-iocommons-io${commons.io.version}org.apache.poipoi-ooxml${poi.version}org.apache.velocityvelocity-engine-core${velocity.version}com.alibaba.fastjson2fastjson2${fastjson.version}io.jsonwebtokenjjwt${jjwt.version}com.alibabatransmittable-thread-local${transmittable-thread-local.version}com.ruoyiruoyi-common-core${ruoyi.version}com.ruoyiruoyi-common-swagger${ruoyi.version}com.ruoyiruoyi-common-security${ruoyi.version}com.ruoyiruoyi-common-datascope${ruoyi.version}com.ruoyiruoyi-common-datasource${ruoyi.version}com.ruoyiruoyi-common-seata${ruoyi.version}com.ruoyiruoyi-common-log${ruoyi.version}com.ruoyiruoyi-common-redis${ruoyi.version}com.ruoyiruoyi-api-system${ruoyi.version}ruoyi-authruoyi-gatewayruoyi-visualruoyi-modulesruoyi-apiruoyi-commonpomorg.springframework.cloudspring-cloud-starter-bootstraporg.apache.maven.pluginsmaven-compiler-plugin3.11.0${java.version}${java.version}${project.build.sourceEncoding}org.springframework.bootspring-boot-maven-plugin${spring-boot.version}repackageD:\org.apache.maven.pluginsmaven-dependency-plugin3.6.0publicaliyun nexushttps://maven.aliyun.com/repository/publictruepublicaliyun nexushttps://maven.aliyun.com/repository/publictruefalse

其他需要打成可执行jar的pom修改如下

ruoyi-auth :

com.ruoyiruoyi3.6.34.0.0ruoyi-authruoyi-auth认证授权中心com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-actuatorcom.ruoyiruoyi-common-security${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIP${project.parent.groupId}${project.parent.artifactId}-common-security${project.parent.groupId}${project.parent.artifactId}-api-system${project.parent.groupId}${project.parent.artifactId}-common-core${project.parent.groupId}${project.parent.artifactId}-common-redisorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime${project.parent.artifactId}-common-security,${project.parent.artifactId}-api-system,${project.parent.artifactId}-common-core,${project.parent.artifactId}-common-redis

ruoyi-gateway:

com.ruoyiruoyi3.6.34.0.0ruoyi-gatewayruoyi-gateway网关模块org.springframework.cloudspring-cloud-starter-gatewaycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelcom.alibaba.cloudspring-cloud-alibaba-sentinel-gatewaycom.alibaba.cspsentinel-datasource-nacosorg.springframework.bootspring-boot-starter-actuatororg.springframework.cloudspring-cloud-loadbalancerpro.fessionalkaptchacom.ruoyiruoyi-common-redisio.springfoxspringfox-swagger-ui${swagger.fox.version}io.springfoxspringfox-swagger2${swagger.fox.version}${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIP<!-- 不排除的依赖,依赖的项目自身依赖,不去除,从上面RuoYi Common Redis找,一级一级找,凡是com.ruoyi,都需要排除-->${project.parent.groupId}${project.parent.artifactId}-common-core${project.parent.groupId}${project.parent.artifactId}-common-redisorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime${project.parent.artifactId}-common-core,${project.parent.artifactId}-common-redis

ruoyi- monitor:

com.ruoyiruoyi-visual3.6.34.0.0ruoyi-visual-monitorruoyi-visual-monitor监控中心de.codecentricspring-boot-admin-starter-server${spring-boot-admin.version}com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-security${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIPnon-existsnon-existsorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime

ruoyi-file:

com.ruoyiruoyi-modules3.6.34.0.0ruoyi-modules-fileruoyi-modules-file文件服务com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-actuatorcom.github.tobatofastdfs-clientio.miniominio${minio.version}com.ruoyiruoyi-api-systemcom.ruoyiruoyi-common-swagger${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIP<!-- 不排除的依赖,依赖的项目自身依赖,不去除,从上面RuoYi Common Redis找,一级一级找,凡是com.ruoyi,都需要排除-->${project.parent.groupId}ruoyi-api-system${project.parent.groupId}ruoyi-common-redis${project.parent.groupId}ruoyi-common-swaggerorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntimeruoyi-api-system,ruoyi-common-core,ruoyi-common-swagger

ruoyi-gen:

com.ruoyiruoyi-modules3.6.34.0.0ruoyi-modules-genruoyi-modules-gen代码生成com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-actuatorio.springfoxspringfox-swagger-ui${swagger.fox.version}org.apache.velocityvelocity-engine-corecom.mysqlmysql-connector-jcom.ruoyiruoyi-common-logcom.ruoyiruoyi-common-swagger${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIPnon-existsnon-existsorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime

ruoyi-job:

com.ruoyiruoyi-modules3.6.34.0.0ruoyi-modules-jobruoyi-modules-job定时任务com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-actuatorio.springfoxspringfox-swagger-ui${swagger.fox.version}org.quartz-schedulerquartzcom.mchangec3p0com.mysqlmysql-connector-jcom.ruoyiruoyi-common-logcom.ruoyiruoyi-common-swagger${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIPnon-existsnon-existsorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime

ruoyi-system:

com.ruoyiruoyi-modules3.6.34.0.0ruoyi-modules-systemruoyi-modules-system系统模块com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.cloudspring-cloud-starter-alibaba-sentinelorg.springframework.bootspring-boot-starter-actuatorio.springfoxspringfox-swagger-ui${swagger.fox.version}com.mysqlmysql-connector-jcom.ruoyiruoyi-common-datasourcecom.ruoyiruoyi-common-datascopecom.ruoyiruoyi-common-logcom.ruoyiruoyi-common-swagger${project.artifactId}org.springframework.bootspring-boot-maven-pluginrepackagetrueZIPnon-existsnon-existsorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependenciesD:\ruoyi-lib\${project.artifactId}-libfalsefalseruntime

我这里测试了下放到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 &

例如 nohup java -Dloader.path=/home/ruoyi-lib/ruoyi-gateway-lib,resources,lib -Dfile.encoding=utf-8 -jar ruoyi-gateway.jar &