Package spring boot application with a light jar to run as daemon

794 Views Asked by At

Using Spring-boot 1.5.6 with Java 8 on Debian jessie, built with Maven.

The generated jar is a big fat 70Mo jar, usage as daemon works fine.

How generate a lighter jar, with dependencies jar files in a lib folder somewhere?

Here the current pom.xml I am using:

https://gist.github.com/ebuildy/46e42c06d344707c823d0320d78eea1c

1

There are 1 best solutions below

1
On

Apologies for the unprecise and incorrect answer: By default, the spring-boot-maven-plugin does not honour "provided", but includes every dependency.

I've tried out the linked "thin" extension, but that one did not work for me.

Coming back to my original post, the idea was right: Use the PropertiesLauncher and let it point to some directories where your JARs live.

  1. We need to trigger this launcher. This can be achieved for example via using the layout type "DIR" in the spring-boot-maven-plugin.

  2. Additionally one needs to provide a config file "loader.properties" which contains a property pointing to the directory (or directories) holding the JARs.

  3. In case we want to provide a Spring Boot Executable JAR which does not contain any or just some of the dependencies, we need to exclude the undesired ones. Multiple solutions exist (use the out-of-the-box abilities to exclude them one-by-one, modify the Executable JAR after generating it, enhance the spring-boot-maven-plugin to filter by scope). I chose the last solution.

See the linked GIST for a complete listing.