Creating native image with micronaut and graalvm

Creating native image with micronaut and graalvm

Subscribe to my newsletter and never miss my upcoming articles

In last section we saw , how easy it was to create a project with micronaut. We created our universe savior heroes and called them through our url /super-heroes with their powers .If you have not checked it, you can take a look at below link.

The world these days are moving at fast pace. To start our system it was taking almost 3 seconds. What if it turns out to be too much to call these saviors. Graalvm is there to rescue. We will build native images in this article and start our system in milliseconds. In order to build native image we require graalvm . To install graalvm on your system there are several ways , but now let's use the easy one SDKMAN. If you have not installed SDKMAN , please do it. Its awesome.

To check list of available jdks use following command

sdk list java

From the list choose the graalvm

Screenshot from 2021-08-20 22-14-11.png

Here we will choose 21.2.0.r16-grl

Use the below command to install the graalvm SDK sdk install java 21.2.0.r16-grl

Once It is installed , we need to add native image building capabilities to it.

gu install native-image

Now we are ready to create native images. Use the following command

./mvnw package -Dpackaging=native-image

This step might take sometime depending upon you system configurations. Once done you will see inside target folder there will be a new native binary present . Use it to start the application It our case application name is super-heroes so native is also named same.


You will see logs as following

Screenshot from 2021-08-20 20-40-38.png

Clearly you can see it started in 64 milliseconds which is around 47 times faster than our older effort , which was at 3028 ms , below is the screenshot of running jar than binary.

Screenshot from 2021-08-20 20-42-35.png

If you like my articles you can support me by sharing the articles with your friends, twitter, facebook or any other social media. You can also buy me a coffee output-onlinepngtools.png

Share this