Hack – How 2 add jars 2 springboot classpath with JarLauncher ?

We had a scenario where  we were using the JarLauncher of springboot but had to add additional jars to classpath.

i.e. we would launch the springboot app using the following command

java -jar fat_app.jar

Since springboot when using JarLaunhcer , ignores -classpath or -cp argument of java, our attempt to add a jar via -cp argument fails.

Solution as of now is to modify the pom.xml and change to Properties launcher i.e. change pom.xml as follows

            <configuration>  <!-- added -->
                <layout>ZIP</layout> <!-- to use PropertiesLaunchar -->

But we DID NOT want to do the above.

We wanted to add a jar, without changing the pom.xml

i.e. continue using the JAR Launcher.

When we use the jar launcher i.e. run via the following command

java -jar fat_app.jar
# The main class in JAR manifest 
# is set to 'org.springframework.boot.loader.JarLauncher'

The solution is to go the old java way and provide the main class yourself:

i.e. the solution is

java \
-cp fat_app.jar \
-Dloader.path=<path_to_your_additional_jars> \

# It should work now, even though the main class in manifest 
# of fat_app.jar is set to 'org.springframework.boot.loader.JarLauncher'
# and your additional classes will be picked up by springboot


#Thanks to my ex colleague @Dapeng for the idea