Let’s now produce a native executable for our application. It improves the startup time of the application and produces a minimal disk footprint. The executable would have everything to run the application including the JVM (shrunk to be just enough to run the application), and the application.
Ensure the location of the GraalVM installation is set by checking the appopriate environment variable:
The output should be similar to the following (the relevant part is that it indicates it's using the GraalVM):
openjdk version "17.0.5" 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)
Building the Native Image
pom.xmlis the declaration for the Maven profile named "native":
<profile> <id>native</id> <activation> <property> <name>native</name> </property> </activation> <build> ... <properties> <quarkus.package.type>native</quarkus.package.type> </properties> </profile>
We use a profile because packaging the native image takes a few seconds. However, this compilation time is only incurred once, as opposed to every time the application starts, which is the case with other approaches for building and executing JARs.
quarkus.native.container-runtime. This example uses Podman, so if you're using Docker be sure to update the command accordingly.
mvn clean package -Pnative -DskipTests -Dquarkus.native.container-runtime=podman
In addition to the other JARs normally produced by the
package goal, the native profile creates a file named
Running the Native Image
INFO [io.quarkus] (main) Quarkus x.xx.x started in 0.044s. Listening on: http://[::]:8080 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
psutility. Run the following command in another Terminal:
PID RSS COMMAND 261971 53740 ./target/getting-started-1.0.0-SNAPSHOT-runner
This shows that our process is taking around 53 MB of memory (Resident Set Size, or RSS). Pretty compact!
Note that the RSS and memory usage of any app, including Quarkus, will vary depending your specific environment, and will rise as the application experiences load.
CTRL-Cin its terminal.