Backend Development 6 min read

How to Slim Down SpringBoot Jar Packages for Faster Deployment

This guide explains how to analyze the structure of a SpringBoot jar, separate your own classes from third‑party dependencies, reconfigure Maven packaging to produce a much smaller zip‑layout jar, and deploy it efficiently by uploading only the necessary libraries.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
How to Slim Down SpringBoot Jar Packages for Faster Deployment

SpringBoot provides a convenient framework for rapid development, but the default executable jar can be tens or hundreds of megabytes, making uploads to remote servers slow. This article shows how to slim down a SpringBoot jar for faster deployment.

Idea

By inspecting the jar, we see three main sections: BOOT-INF , META-INF , and org . Inside BOOT-INF there are classes (your compiled code, usually a few megabytes) and lib (all Maven dependencies, often dozens of megabytes). The solution is to upload the classes part together with the required dependencies separately.

Slim Deployment

1. Normal Packaging

The default Maven configuration uses the SpringBoot Maven plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

After building, unzip the generated jar (or rename it to .zip ) and extract the BOOT-INF/lib directory.

2. Change Packaging Mode

Modify the plugin configuration to produce a zip‑layout jar and specify the main class:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.zyxx.DeclareApplication</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>

mainClass : specifies the entry point of the application.

layout : set to ZIP (uppercase) to produce a zip‑style jar.

includes : you can add additional dependency jars here.

repackage : removes unnecessary files, keeping a minimal structure.

3. Re‑package

Run mvn package again. The resulting jar is only a few megabytes because the heavy lib folder is excluded.

Upload and Start

Upload the slim jar together with the previously extracted lib directory to the server. Then start the application with:

nohup java -Dloader.path=./lib -jar ./sbm-0.0.1-SNAPSHOT.jar &

-Dloader.path : points to the directory containing the Maven dependency jars.

sbm-0.0.1-SNAPSHOT.jar : the name of your slim jar.

nohup and & : run the process in the background.

Conclusion

Using this slim deployment method, you only need to upload the small jar and the dependency libraries once, which greatly reduces upload time for each iteration and speeds up the overall deployment process.

JavaperformanceMavenSpringBootJar SlimmingBackend Deployment
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login 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.