Java教程

瘦身打包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(Maven)项目的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!