How to Slim Down Spring Boot JARs for Faster Deployment

This guide explains why Spring Boot JARs become oversized when packed with many dependencies, demonstrates how to extract and reuse the lib folder, modify Maven settings to exclude embedded libraries, and run a much smaller JAR together with the external libs for efficient deployment.

Programmer DD
Programmer DD
Programmer DD
How to Slim Down Spring Boot JARs for Faster Deployment

Introduction

SpringBoot is easy to deploy, but when the server is on the public network, the generated JAR can be huge, especially when many dependencies such as Spring Cloud are included, making adjustments painful.

Jar Size Before Slimming

In a typical SpringBoot JAR, most of the disk space is taken by external dependency JARs located in BOOT-INF/lib. An example shows an 18.18 MB JAR where the BOOT-INF/lib directory alone occupies nearly 18 MB.

Solution

Three steps are provided to produce a slimmer JAR that does not embed the dependency libraries.

Step 1: Build the normal JAR and extract the lib folder

Run mvn clean install in the project root, then unzip the resulting JAR and copy the BOOT-INF/lib directory to the target location.

Execute mvn clean install again.

Step 2: Modify pom.xml to exclude the lib folder from the packaged JAR

After adjusting the Maven configuration (shown in the image), rebuild the project with mvn clean install. The new JAR is dramatically smaller because external JARs are no longer bundled.

Step 3: Run the slim JAR together with the extracted lib folder

Place the lib folder from Step 1 and the new JAR in the same directory and start the application with the command shown in the image (using -Dloader.path=lib).

Alternatively, you can use Maven to copy the required JARs.

Notes

Once the project architecture is fixed, the set of JAR dependencies rarely changes; most changes are in business logic.

Future business‑logic updates only require recompiling the lightweight project, greatly improving deployment efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MavenSpring BootJar Optimization
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.