Springboot分资源打包,便于管理

服务器每次更换jar包即可,分包之后jar包基本就四几十kb大小

pom文件

只需指定入口类
<build>
   <plugins>
       <!--1.编译jar -->
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>${maven.compiler.source}</source>
               <target>${maven.compiler.source}</target>
               <encoding>${project.build.sourceEncoding}</encoding>
           </configuration>
       </plugin>
       <!-- 2.打JAR包 -->
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-jar-plugin</artifactId>
           <configuration>
               <!-- 不打包资源文件(配置文件和依赖包分开) -->
               <!-- 打包时剔除 properties文件-->
               <excludes>
                   <exclude>*.properties</exclude>
                   <exclude>*/**/*.properties</exclude>
                   <exclude>*.yml</exclude>
                   <exclude>*.xml</exclude>
               </excludes>
               <archive>
                   <manifest>
                       <addClasspath>true</addClasspath>
                       <!-- MANIFEST.MF 中 Class-Path 加入前缀 -->
                       <classpathPrefix>lib/</classpathPrefix>
                       <!-- jar包不包含唯一版本标识 -->
                       <useUniqueVersions>false</useUniqueVersions>
                       <!--指定入口类 -->
                       <mainClass>入口类</mainClass>
                   </manifest>
                   <manifestEntries>
                       <!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
                       <Class-Path>./resources/</Class-Path>
                   </manifestEntries>
               </archive>
               <outputDirectory>${project.build.directory}/dis</outputDirectory>
           </configuration>
       </plugin>
       <!-- 3.该插件的作用是用于复制依赖的jar包到指定的文件夹里 -->
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-dependency-plugin</artifactId>
           <version>2.8</version>
           <executions>
               <execution>
                   <id>copy-dependencies</id>
                   <phase>package</phase>
                   <goals>
                       <goal>copy-dependencies</goal>
                   </goals>
                   <configuration>
                       <outputDirectory>${project.build.directory}/dis/lib/</outputDirectory>
                   </configuration>
               </execution>
           </executions>
       </plugin>
       <!-- 4.该插件的作用是用于复制指定的文件 -->
       <plugin>
           <artifactId>maven-resources-plugin</artifactId>
           <executions>
               <execution>
                   <id>copy-resources</id>
                   <phase>package</phase>
                   <goals>
                       <goal>copy-resources</goal>
                   </goals>
                   <configuration>
                       <resources>
                           <resource>
                               <directory>src/main/resources</directory>
                               <includes>
                                   <include>*.properties</include>
                                   <include>*/**/*.properties</include>
                                   <include>*.yml</include>
                                   <include>*.xml</include>
                               </includes>
                           </resource>
                       </resources>
                       <outputDirectory>${project.build.directory}/dis/resources</outputDirectory>
                   </configuration>
               </execution>
           </executions>
       </plugin>
       <!-- 5.SpringBoot 打包插件,把 maven-jar-plugin 打成的jar包重新打成可运行jar包 -->
       <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>
           <configuration>
               <!--重写包含依赖,包含不存在的依赖,jar里没有pom里的依赖 -->
               <includes>
                   <include>
                       <groupId>null</groupId>
                       <artifactId>null</artifactId>
                   </include>
               </includes>
               <layout>ZIP</layout>
               <!--使用外部配置文件,jar包里没有资源文件 -->
               <addResources>true</addResources>
           </configuration>
           <executions>
               <execution>
                   <goals>
                       <goal>repackage</goal>
                   </goals>
               </execution>
           </executions>
       </plugin>
   </plugins>
</build>

效果展示

结果

说明

dis目录下面:
	lib目录存放jar包
	resources目录存放配置文件
	外层一个很小的应用jar
部署只需要将dis目录下面的文件放在同级目录下即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值