Guide For Running Spring Native Application

Posted by dogukanhan on May 02, 2021 · 2 mins read

Guide For Running Spring Native Application

      In this writing, I will show how to run the spring-native application in steps. Before starting the guide, I want to mention spring-native and why we should try it. Spring-native images are compiled to native by using GraalVM to provide a new way to deploy Spring applications.

      Native Spring applications can be deployed as a standalone executable (no JVM installation required) and offer interesting characteristics including almost instant startup (typically < 100ms), instant peak performance, and lower memory consumption at the cost of longer build times and fewer runtime optimizations than the JVM. 1

1. Download GrallVM

To create the native image, we must install GrallVM because native-image functionality is only supported by GrallVM. https://www.graalvm.org/downloads/ After downloading, extract it and add it to your path so you can access the javac command while using your command-line tool.

2. Install Native Image to GrallVM

GrallVM doesn’t come with the native image extension, which you must install using the command-line utility.

gu install native-image

3. Install Maven

A dependency manager/build tool is required. You must have Maven( or Gradle) to run a spring-native application. https://maven.apache.org/download.cgi After downloading, add it to your path.

4. Install GCC and libz.a

GCC and libz.a are required for compiling to the native image. Install them with using your OS’s package manager. sudo apt-get install gcc libz.a if you are using debian based distros.

5. Clone spring-native Repository

You may choose to download the repository as zip in here or you can clone it with using git application.

git clone https://github.com/spring-projects-experimental/spring-native

5. Create Native Image of Sample Application and Run

Open samples/commandlinerunner directory in your terminal and call build.sh file which builds the sample application as native and shows the result.

cd samples/commandlinerunner

./build.sh