GithubHelp home page GithubHelp logo

andifalk / custom-spring-boot-launch-script Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 112 KB

Demo for packaging a spring boot executable using a custom embedded launch script

Shell 91.80% Java 8.20%
spring-boot executable-jar maven gradle launch-script customization java

custom-spring-boot-launch-script's Introduction

Spring Boot Launch Demo

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.

Using Customized Launch Script

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)

This project shows how to use a customized launch script to create an executable jar. The custom-launch-script.sh 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.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
        <embeddedLaunchScript>custom-launch-script.sh</embeddedLaunchScript>
    </configuration>
</plugin>

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

./target/boot-launch-demo-1.0.jar

Gradle Build

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

bootJar {
    launchScript {
        script = file("$projectDir/custom-launch-script.sh")
    }
}

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

./build/libs/boot-launch-demo-1.0.jar

Reference Documentation

For further reference, please consider the following sections:

custom-spring-boot-launch-script's People

Contributors

andifalk avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.