Native Executable
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:
echo $GRAALVM_HOME
java
executable:
$GRAALVM_HOME/bin/java -version
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.xml
is 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 getting-started-1.0.0-SNAPSHOT-runner
.
Running the Native Image
target/getting-started-1.0.0-SNAPSHOT-runner
INFO [io.quarkus] (main) Quarkus x.xx.x started in 0.044s. Listening on: http://[::]:8080 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
ps
utility. 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.
curl localhost:8080/hello
Cleaning Up
CTRL-C
in its terminal.