How to Slim Down SpringBoot JAR Files for Faster Deployment

This guide explains why SpringBoot JARs become large when including many dependencies, shows how to inspect the packaged lib folder, and provides step‑by‑step instructions—including Maven configuration changes and command‑line tricks—to produce a slimmer JAR without bundled external libraries, improving deployment efficiency.

Programmer DD
Programmer DD
Programmer DD
How to Slim Down SpringBoot JAR Files for Faster Deployment

Introduction

SpringBoot is easy to deploy, but when the server is on the public cloud the generated JAR can become huge, especially if many open‑source components such as Spring Cloud are included. Adjusting a running application in such cases is painful.

Jar Size Before Slimming

When deploying a web application, Tomcat supports incremental updates and SpringBoot can do the same. The bulk of the disk usage in a SpringBoot JAR comes from external dependency JARs located in BOOT-INF/lib. After running mvn clean install and opening the JAR, the BOOT-INF/lib directory may occupy almost the entire size (e.g., 18 MB of an 18.18 MB JAR).

Solution

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

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

Step 2: Modify pom.xml to produce a JAR without the lib folder

Adjust the Maven configuration as shown in the image below, then run mvn clean install again.

The resulting JAR is dramatically smaller, and external JARs are no longer bundled.

Step 3: Run the slimmed JAR

Place the extracted lib folder from Step 1 together with the new JAR, then start the application with:

java -jar your-app.jar -Dloader.path=lib

Alternatively, you can export the required JARs directly from Maven:

mvn dependency:copy-dependencies -DoutputDirectory=lib

Notes

Replace /path/to/ with the actual path and set -Dloader.path to the lib folder location.

Final directory structure:

Explanation

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

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

mavenSpringBootDeployment OptimizationJar Shrinking
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.