Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Executable Jar File Without Dependencies

What is the easiest way to build spring boot jar file without its dependencies? Basically I should be able to keep dependency jar files in a separate folder.

Currently I'm using spring boot maven plugin, however, it creates a Fat jar file with all dependencies.

like image 462
Yasitha Waduge Avatar asked Nov 09 '15 10:11

Yasitha Waduge


People also ask

How do I create a standalone jar executable spring boot?

Spring Boot provides an option for creating a self-contained executable jar file to run in production. To create an executable jar, we need the spring-boot-maven-plugin in our pom. xml file (check section 2 for detail). Run mvn package command to create an executable jar.

How do I run an executable jar in spring boot?

The Spring Boot Maven Pluginimplement a custom ClassLoader to locate and load all the external jar libraries now nested inside the package. automatically find the main() method and configure it in the manifest, so we don't have to specify the main class in our java -jar command.

Does a jar file contain all dependencies?

Normally, when we package a project into a jarW file, the jar file doesn't contain its dependencies, so the dependency jar files would need to be included in the classpathW in order to execute a class in the project's jar file that uses one of the dependencies.


2 Answers

Just do not use spring-boot-maven-plugin at all and use JAR packaging. This way the build wouldn't package dependencies into the JAR.

like image 197
luboskrnac Avatar answered Oct 02 '22 07:10

luboskrnac


spring-boot-maven-plugin has option for repackaging that puts dependencies inside (making uber jar)

You can disable repackaging or make repackaged .jar go with other classifier [2]

  1. http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html

  2. http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/repackage-classifier.html

like image 44
Paul Verest Avatar answered Oct 02 '22 07:10

Paul Verest