gitee地址:ruoyi-pom-config: 用来修改ruoyi-cloud的pom文件示例,第三方jar包抽取打包
以若依微服务项目为说明示例,需要用git下载下来结合理解,后端项目结构
图一:
红圈一的pom为最父级的pom文件
最父级 pom文件内容如下
4.0.0 com.ruoyi ruoyi 3.6.3 ruoyi http://www.ruoyi.vip 若依微服务系统 3.6.3 UTF-8 UTF-8 1.8 2.7.13 2021.0.8 2021.0.5.0 2.7.10 3.0.0 1.6.2 1.27.2 2.3.3 1.4.7 1.2.16 3.5.2 2.13.0 2.3 2.0.39 0.9.1 8.2.2 4.1.2 2.14.3 org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import com.alibaba.cloud spring-cloud-alibaba-dependencies ${spring-cloud-alibaba.version} pom import org.springframework.boot spring-boot-dependencies ${spring-boot.version} pom import com.github.tobato fastdfs-client ${tobato.version} io.swagger swagger-models ${swagger.core.version} io.swagger swagger-annotations ${swagger.core.version} pro.fessional kaptcha ${kaptcha.version} com.github.pagehelper pagehelper-spring-boot-starter ${pagehelper.boot.version} commons-io commons-io ${commons.io.version} org.apache.poi poi-ooxml ${poi.version} org.apache.velocity velocity-engine-core ${velocity.version} com.alibaba.fastjson2 fastjson2 ${fastjson.version} io.jsonwebtoken jjwt ${jjwt.version} com.alibaba transmittable-thread-local ${transmittable-thread-local.version} com.ruoyi ruoyi-common-core ${ruoyi.version} com.ruoyi ruoyi-common-swagger ${ruoyi.version} com.ruoyi ruoyi-common-security ${ruoyi.version} com.ruoyi ruoyi-common-datascope ${ruoyi.version} com.ruoyi ruoyi-common-datasource ${ruoyi.version} com.ruoyi ruoyi-common-seata ${ruoyi.version} com.ruoyi ruoyi-common-log ${ruoyi.version} com.ruoyi ruoyi-common-redis ${ruoyi.version} com.ruoyi ruoyi-api-system ${ruoyi.version} ruoyi-auth ruoyi-gateway ruoyi-visual ruoyi-modules ruoyi-api ruoyi-common pom org.springframework.cloud spring-cloud-starter-bootstrap org.apache.maven.plugins maven-compiler-plugin 3.11.0 ${java.version} ${project.build.sourceEncoding} org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} repackage D:\ public aliyun nexus https://maven.aliyun.com/repository/public true public aliyun nexus https://maven.aliyun.com/repository/public true false
先重点看最父级pom文件,下面图中的红圈部分
图二:
红圈二是所有子模块中有启动类的,需要打包成可执行jar包的,对其pom中spring-boot-maven-plugin版本的统一管理,ruoyi-gateway,ruoyi-auth,ruoyi-visual以及ruoyi-modules聚合模块下的所有子模块
图三:
这些子模块的pom中都有如下图所示部分
图四:
因为它们都有启动类,都会被打包成可执行的jar包 ,其他诸如ruoyi-common模块下的子模块
图五:
ruoyi-api下的子模块
图六:
这些子模块的pom中没有图四部分,这些pom中也没有
只有聚合模块,就是有子模块的如ruoyi-api,ruoyi-common,ruoyi-modules,RuoYi-Cloud这些文件夹根目录下都会有一个聚合其子模块的pom文件
包含
图七:
如果pom文件中没有
如ruoyi-common,ruoyi-api下的所有子模块的pom,则默认会打成jar包,但是这些子模块pom中也没有图四部分,所有这些模块打的jar包只是普通的jar包,就像我们引入的其他第三方依赖的jar一样,这些普通jar是无法通过java -jar xxx.jar运行的,因为,没有使用spring-boot-maven-plugin,也没有启动类
红圈一说明:
只有最父级的聚合pom文件有此部分,其他下属子模块中,属于聚合模块的pom,即有
maven-compiler-plugin 与spring-boot-maven-plugin 区别如下:
从图二中可以看到最父级的pom使用的是 maven-compiler-plugin
这个是maven用来编译管理所有可执行的jar依赖包的,放入一个仓库,方便管理
最父级pom这里,加上这个,即可把所有可执行jar包打包到指定文件夹下
抽离第三方jar方式,最父级pom添加
4.0.0 com.ruoyi ruoyi 3.6.3 ruoyi http://www.ruoyi.vip 若依微服务系统 3.6.3 UTF-8 UTF-8 1.8 2.7.13 2021.0.8 2021.0.5.0 2.7.10 3.0.0 1.6.2 1.27.2 2.3.3 1.4.7 1.2.16 3.5.2 2.13.0 2.3 2.0.39 0.9.1 8.2.2 4.1.2 2.14.3 org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import com.alibaba.cloud spring-cloud-alibaba-dependencies ${spring-cloud-alibaba.version} pom import org.springframework.boot spring-boot-dependencies ${spring-boot.version} pom import com.github.tobato fastdfs-client ${tobato.version} io.swagger swagger-models ${swagger.core.version} io.swagger swagger-annotations ${swagger.core.version} pro.fessional kaptcha ${kaptcha.version} com.github.pagehelper pagehelper-spring-boot-starter ${pagehelper.boot.version} commons-io commons-io ${commons.io.version} org.apache.poi poi-ooxml ${poi.version} org.apache.velocity velocity-engine-core ${velocity.version} com.alibaba.fastjson2 fastjson2 ${fastjson.version} io.jsonwebtoken jjwt ${jjwt.version} com.alibaba transmittable-thread-local ${transmittable-thread-local.version} com.ruoyi ruoyi-common-core ${ruoyi.version} com.ruoyi ruoyi-common-swagger ${ruoyi.version} com.ruoyi ruoyi-common-security ${ruoyi.version} com.ruoyi ruoyi-common-datascope ${ruoyi.version} com.ruoyi ruoyi-common-datasource ${ruoyi.version} com.ruoyi ruoyi-common-seata ${ruoyi.version} com.ruoyi ruoyi-common-log ${ruoyi.version} com.ruoyi ruoyi-common-redis ${ruoyi.version} com.ruoyi ruoyi-api-system ${ruoyi.version} ruoyi-auth ruoyi-gateway ruoyi-visual ruoyi-modules ruoyi-api ruoyi-common pom org.springframework.cloud spring-cloud-starter-bootstrap org.apache.maven.plugins maven-compiler-plugin 3.11.0 ${java.version} ${project.build.sourceEncoding} org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} repackage D:\ org.apache.maven.plugins maven-dependency-plugin 3.6.0 public aliyun nexus https://maven.aliyun.com/repository/public true public aliyun nexus https://maven.aliyun.com/repository/public true false
其他需要打成可执行jar的pom修改如下
ruoyi-auth :
com.ruoyi ruoyi 3.6.3 4.0.0 ruoyi-auth ruoyi-auth认证授权中心 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator com.ruoyi ruoyi-common-security ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP ${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-redis org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime ${project.parent.artifactId}-common-security, ${project.parent.artifactId}-api-system, ${project.parent.artifactId}-common-core, ${project.parent.artifactId}-common-redis
ruoyi-gateway:
com.ruoyi ruoyi 3.6.3 4.0.0 ruoyi-gateway ruoyi-gateway网关模块 org.springframework.cloud spring-cloud-starter-gateway com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel com.alibaba.cloud spring-cloud-alibaba-sentinel-gateway com.alibaba.csp sentinel-datasource-nacos org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-loadbalancer pro.fessional kaptcha com.ruoyi ruoyi-common-redis io.springfox springfox-swagger-ui ${swagger.fox.version} io.springfox springfox-swagger2 ${swagger.fox.version} ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP ${project.parent.groupId} ${project.parent.artifactId}-common-core ${project.parent.groupId} ${project.parent.artifactId}-common-redis org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime ${project.parent.artifactId}-common-core, ${project.parent.artifactId}-common-redis
ruoyi- monitor:
com.ruoyi ruoyi-visual 3.6.3 4.0.0 ruoyi-visual-monitor ruoyi-visual-monitor监控中心 de.codecentric spring-boot-admin-starter-server ${spring-boot-admin.version} com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-security ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP non-exists non-exists org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime
ruoyi-file:
com.ruoyi ruoyi-modules 3.6.3 4.0.0 ruoyi-modules-file ruoyi-modules-file文件服务 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-actuator com.github.tobato fastdfs-client io.minio minio ${minio.version} com.ruoyi ruoyi-api-system com.ruoyi ruoyi-common-swagger ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP ${project.parent.groupId} ruoyi-api-system ${project.parent.groupId} ruoyi-common-redis ${project.parent.groupId} ruoyi-common-swagger org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime ruoyi-api-system, ruoyi-common-core, ruoyi-common-swagger
ruoyi-gen:
com.ruoyi ruoyi-modules 3.6.3 4.0.0 ruoyi-modules-gen ruoyi-modules-gen代码生成 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-actuator io.springfox springfox-swagger-ui ${swagger.fox.version} org.apache.velocity velocity-engine-core com.mysql mysql-connector-j com.ruoyi ruoyi-common-log com.ruoyi ruoyi-common-swagger ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP non-exists non-exists org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime
ruoyi-job:
com.ruoyi ruoyi-modules 3.6.3 4.0.0 ruoyi-modules-job ruoyi-modules-job定时任务 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-actuator io.springfox springfox-swagger-ui ${swagger.fox.version} org.quartz-scheduler quartz com.mchange c3p0 com.mysql mysql-connector-j com.ruoyi ruoyi-common-log com.ruoyi ruoyi-common-swagger ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP non-exists non-exists org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime
ruoyi-system:
com.ruoyi ruoyi-modules 3.6.3 4.0.0 ruoyi-modules-system ruoyi-modules-system系统模块 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config com.alibaba.cloud spring-cloud-starter-alibaba-sentinel org.springframework.boot spring-boot-starter-actuator io.springfox springfox-swagger-ui ${swagger.fox.version} com.mysql mysql-connector-j com.ruoyi ruoyi-common-datasource com.ruoyi ruoyi-common-datascope com.ruoyi ruoyi-common-log com.ruoyi ruoyi-common-swagger ${project.artifactId} org.springframework.boot spring-boot-maven-plugin repackage true ZIP non-exists non-exists org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies D:\ruoyi-lib\${project.artifactId}-lib false false runtime
我这里测试了下放到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 &