其他分享
首页 > 其他分享> > 瘦身打包Springboot(Maven)项目

瘦身打包Springboot(Maven)项目

作者:互联网

正常情况下,springboot项目打包完后占很大的空间,最小的也有16M,有些一百多M,主要还是lib目录下的依赖太多

瘦身打包springboot的方法是,只打包需要的依赖

步骤1: 正常编译JAR包,解压出lib文件夹

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

 

步骤2: 修改pom.xml配置,编译出不带 lib 文件夹的Jar包

<build>

    <plugins>

        <plugin>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-maven-plugin</artifactId>

            <configuration>

                <layout>ZIP</layout>

                <includes>

                    <include>

                        <groupId>nothing</groupId>

                        <artifactId>nothing</artifactId>

                    </include>

                </includes>

            </configuration>

            <executions>

                <execution>

                    <goals>

                        <goal>repackage</goal>

                    </goals>

                </execution>

            </executions>

        </plugin>

    </plugins>

</build>

 

步骤3: 运行编译后的Jar包

Java -jar -Dloader.path=./BOOT-INF/lib web-demo-0.0.1-SNAPSHOT.jar

“./BOOT-INF/lib”要根据实际情况填写

标签:Springboot,lib,步骤,boot,Maven,编译,瘦身,打包,springboot
来源: https://blog.csdn.net/weixin_42316006/article/details/119429343