Custom launch script for Spring Boot executable

March 27, 2020


In addition to running Spring Boot applications by using java -jar, it is also possible to make fully executable applications for Unix systems. A fully executable jar can be executed like any other executable binary or it can be registered with init.d or systemd.

Details on this are described in the Spring Boot reference docs.

To achieve this the Spring Boot Maven or Gradle plugins repackage the jar file and add an embedded shell script to the jar. This default shell script is provided by Spring Boot and should run on most Unix systems without any issues.

But sometimes the script does not work on your operating system for any reason (i.e. using a legacy version or the shell is not compatible with the default shell script).

Using Customized Launch Script

This article shows how to use a customized launch script to create an executable jar. The used here just adds an additional line echoRed "My custom script is running!!!!" to the script to show that the executable really uses the custom one instead of the default script.

The required steps are shown for

  • Maven based Spring Boot projects
  • Gradle based Spring Boot projects

Maven Build

To use the custom script you need to add this snippet to your maven pom to the spring boot plugin configuration section.


Now perform a ./mvnw clean package and after this execute the app:


Gradle Build

To use the custom script you need to add this snippet to your build.gradle file.

bootJar {
    launchScript {
        script = file("$projectDir/")

Now perform a ./gradlew clean build and after this execute the app:


That’s it. You can grab the corresponding source code from my GitHub repository.

Nifty tech tag lists fromĀ Wouter Beeftink

Commit: "d9d9f38"

LastMod Date using GitInfo: d9d9f38