精简springboot打包后的体积,提升启动速度

改动之前5分钟,改动之后

[2024-04-11 13:43:37.100]
[2024-04-11 13:44:16.849]

这里涉及两个打包插件

maven-dependency-plugin和spring-boot-maven-plugin
将依赖放置单独的文件夹
 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.2</version> <!-- 请根据需要使用适当的版本 -->
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

  精简jar体积

 <plugin>
        <configuration>
          <includeSystemScope>true</includeSystemScope>
        </configuration>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot.version}</version>
        <executions>
          <execution>
              <id>repackage</id>
              <configuration>
                <skip>true</skip>
              </configuration>
          </execution>
        </executions>
      </plugin>

  

 

 

 

 这里的启动命令需要调整

java -cp "a.jar;lib/*" com.java.Application

  

其中com.java.Application为启动类的路径

  

posted @ 2024-04-11 15:23  不忘初心2021  阅读(34)  评论(0编辑  收藏  举报