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. https://sdkman.io/
To check list of available jdks use following command
sdk list java
From the list choose the graalvm
Here we will choose
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
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.