Building Native Applications with Quarkus

Building Native Applications with Quarkus

In the previous post, we talked about getting started with Quarkus and created a simple REST service. In this post, we will build the service as a native application and run it locally on a Windows machine.

Setting up the development environment

Next to the quarkus-cli installation, some addition setup is needed if you want to compile your app into a native executable.

  1. Docker desktop.
  2. GraalVM.
  3. Native image tool.
  4. Visual Studio 2017 Visual C++ Build Tools.

Docker desktop

Installing docker desktop is pretty easy and straightforward. You could use the official docker documentation (Install Docker Desktop on Windows) to set up a working docker container runtime.

After installation, please make sure to keep the docker runtime running because quarkus needs it to build the native executable.

GraalVM

First, we need to download GraalVM. I have used the official GitHub release page to download the appropriate distribution.

After the completion of the download, unzip the files into a location of your choice.

The next step is to configure GraalVM. Therefore, you need to add some new environment variables and modify existing ones.

When you open your system environment variables, add a new variable for GraalVM (GRAALVM_HOME):

JAVA_HOME should also point to the same folder, so make sure to modify that as well.

Next, we need to add the GraalVM into our Windows path:

At this stage, GraalVM is installed and configured correctly!

Installing Native image tool

As soon as GraalVM is configured correctly, run the following command to install the native image tool.

gu install native-image

Visual Studio 2017 Visual C++ Build Tools

Downloading Visual Studio build tools can be done via the official Microsoft website.

Download Visual Studio Tools - Install Free for Windows, Mac, Linux
Download Visual Studio IDE or VS Code for free. Try out Visual Studio Professional or Enterprise editions on Windows, Mac.

Build the native application

After completing setting up the environment, we can now compile our code into a native windows executable.

First, open the native tools cmd:

Navigate to the folder which contains the Quarkus project and run the following command:

quarkus build --native

You would notice that GraalVM is used to build the native executable in the cmd:

Quarkus also makes use of the maven-failsafe-plugin to run integration tests compile time by actually starting the Quarkus application and running tests against it.

Running the native executable

Let's check the target folder of our project:

We can notice that an .exe file is created, which represents our application available as an executable file. Let's run the file by double-clicking on it and call one of the endpoints in the browser:

Application started

We can see that the response was returned by the service after sending a GET request via the browser to the /hello endpoint.

Thank you for reading my blog. Please make sure to check out the other Quarkus related articles by visiting the Quarkus section of my blog.

Update cookies preferences