How to Reduce SpringBoot Jar Size for Faster Deployment
This article explains why SpringBoot jars become large when packaged with many dependencies, and provides a step‑by‑step method—extracting the lib folder, adjusting the pom.xml to omit it, rebuilding, and running the slimmed jar with external libraries—to significantly shrink the final artifact and speed up deployment.
SpringBoot applications are easy to deploy, but when the service runs on a public cloud the generated JAR can become huge, especially if many libraries such as SpringCloud are included, making updates and deployments painful.
Step 1: Build the normal JAR and extract the BOOT-INF/lib folder. Run mvn clean install in the project root, then unzip the resulting JAR and copy the BOOT-INF/lib directory to a separate location.
Step 2: Modify pom.xml to produce a JAR without the embedded libraries. The article shows a sample POM configuration (image omitted) that excludes the lib folder from the final artifact. After editing, run mvn clean install again.
The rebuilt JAR is dramatically smaller because external JARs are no longer bundled.
Step 3: Run the slimmed JAR together with the extracted libraries. Place the previously saved lib folder and the new JAR in the same directory and start the application with: java -Dloader.path=./lib -jar your‑app.jar Alternatively, you can use Maven to copy only the required JARs with the command shown in the article (image omitted).
Note: replace /path/to/ with the actual path to your lib directory.
The final directory layout looks like:
In practice, once a project's architecture is fixed, the set of JAR dependencies rarely changes; only business logic evolves. By rebuilding only the lightweight JAR when business code changes, deployment becomes much faster.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
