• spring boot 打jar包分离lib和resources


    为什么要配置、依赖文件分离:

    1.在传统jar包中,所有文件都打包到一个jar包中,jar非常臃肿,在进行服务更新部署时非常不便,而且传输不稳定时导致传输失败。如果过实行文件分离、在依赖不改变的情况下,仅仅上传更新后的 编译文件是非常xxxxxxxxxxxxxxxxxxxxxxxxxxxx方便的。

    1. 如果要修改一些配置文件:properties、xml,静态文件等可以直接在服务器上编辑。

    那么怎么实行配置、依赖文件分离呢?

    插件介绍

    1. maven-jar-plugin 这个插件式专门用来打包用的,可以配置需要打包进去的文件,程序的入口类等。
    2. maven-resources-plugin 这个插件是用来拷贝资源文件的。
    3. maven-maven-dependency-plugin 这个插件是用来拷贝依赖库的。
    4. maven-assembly-plugin 可以说包含了以上插件的功能,但是可以做到更精细的控制。
    5. spring-boot-maven-plugin 这个不用说,springboot 项目最重要的插件,整个项目的打包处理过程还是要依附于它。

    打包成可执行jar,不仅仅局限SpringBoot项目(主入口函数存在)

    maven-jar-plugin 插件打包jar

    在pom文件中配置,但是这样 依赖的jar并不会打进来(后面会有解决方法),适用不需要依赖文件的项目。

    1. org.apache.maven.plugins
    2. maven-jar-plugin
    3. 2.3
    4. true
    5. xxx.xxx.Main
    6. ${project.build.directory}
    maven-assembly-plugin 插件打包jar
    1. <plugin>
    2. <artifactId>maven-assembly-pluginartifactId> <configuration> <appendAssemblyId>falseappendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependenciesdescriptorRef> descriptorRefs> <archive> <manifest> <mainClass>xxx.xxx.MainmainClass> manifest> archive> configuration> <executions> <execution> <id>make-assemblyid> <phase>packagephase> <goals> <goal>assemblygoal> goals> execution> executions> plugin>

    打包SpringBoot 项目

    方案一、
    1. <plugins>
    2. <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-jar-pluginartifactId> <configuration> <archive> <manifest> <addClasspath>trueaddClasspath> <classpathPrefix>lib/classpathPrefix> <useUniqueVersions>falseuseUniqueVersions> <mainClass>xxx.xxx.ApplicationmainClass> manifest> <manifestEntries> <Class-Path>/resourcesClass-Path> manifestEntries> archive> <outputDirectory>${project.build.directory}/disoutputDirectory> configuration> plugin> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-dependency-pluginartifactId> <executions> <execution> <id>copy-dependenciesid> <phase>packagephase> <goals> <goal>copy-dependenciesgoal> goals> <configuration> <outputDirectory> ${project.build.directory}/dis/lib/ outputDirectory> configuration> execution> executions> plugin> <plugin> <artifactId>maven-resources-pluginartifactId> <executions> <execution> <id>copy-resourcesid> <phase>packagephase> <goals>
  • 相关阅读:
    latex如何保证图片和文字的相对位置不变
    [b01lers2020]Welcome to Earth-1
    DHCP执行流程详解
    学习笔记|IO中断|中断号大于31|中断优先级|简易中央门禁|STC32G单片机视频开发教程(冲哥)|第十六集:IO中断
    TEM和CWEM的优缺点
    【C++】迭代器:遍历容器的利器
    Vue.js核心技术解析与uni-app跨平台实战开发学习笔记 第6章 Vue.js路由 6.1 什么是路由 && 6.2 路由控制组件切换
    【python】flask相关包依赖关系问题
    TrendMicro:Apex One Server 工具文件夹
    Jenkins
  • 原文地址:https://blog.csdn.net/shark1357/article/details/127738479