Backend Development 6 min read

Custom Spring Boot Packaging with External Dependencies Using Maven Plugins

This article explains how to create a Spring Boot fat‑jar that externalizes its dependencies by configuring the spring‑boot‑maven‑plugin and maven‑assembly‑plugin to produce a ZIP layout, then uses the PropertiesLauncher with loader.path to load libraries from a separate libs directory at runtime.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Custom Spring Boot Packaging with External Dependencies Using Maven Plugins

In a typical Spring Boot application the final artifact is a Fat Jar that contains all required dependencies and can be started simply with java -jar xxx.jar . However, the author’s company modifies this approach by moving the dependency jars to an external directory and launching the application with java -Dloader.path=libs -jar xxxx.jar , allowing individual libraries to be replaced without rebuilding the whole package.

The custom packaging is achieved using two Maven plugins:

1. spring-boot-maven-plugin

This official Spring Boot plugin builds the fat jar and supports the standard java -jar xxx.jar launch. By setting the plugin’s layout to ZIP and configuring includes with a non‑existent jar, the resulting jar contains no embedded dependencies, leaving them to be supplied externally.

2. maven-assembly-plugin

The assembly plugin allows flexible definition of what files are packaged. By using include and exclude patterns in assembly.xml , the required dependency jars are extracted into a designated libs folder. Running mvn clean package produces the custom archive, which can be unpacked to reveal the libs directory containing the external jars.

When the application starts, Spring Boot’s org.springframework.boot.loader.Launcher (specifically the PropertiesLauncher because of the ZIP layout) loads classes from BOOT-INF/lib/ by default. By setting loader.path in loader.properties or via the LOADER_PATH environment variable, additional classpath locations such as the external libs directory can be added. The syntax supports comma‑separated paths, e.g., java -jar -Dloader.path=xx1,xx2,public <jarName>.jar , which loads all specified libraries.

This packaging and launch strategy, while uncommon, is valuable for projects with many modular components, as it enables quick replacement of problematic dependencies with minimal impact.

javaBackend DevelopmentMavenSpring Bootpackagingpropertieslauncher
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.