瘦身前的 Jar 包
目录结构如下:
整个 Jar 包 16.7M 但是 BOOT-INF/lib 就占用了将近 16.6 M
解决办法
- 正常编译 Jar 包, 解压出lib文件夹
- 修改 pom.xml 配置,编译出不带 lib 文件夹的 Jar 包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.cgp.jar.SpringBootJarApplication</mainClass>
<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>
配置完成后,再次执行编译
生成的 Jar 包体积明显变小
3. 运行编译后的 Jar 包
将解压出来的lib文件夹、新编译的jar包放在同一个目录, 运行下面命令 就能成功运行
java -Dloader.path=lib -jar spring-boot-jar-0.0.1-SNAPSHOT.jar