This example shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell. This example uses a simple hello world Java application built with Oracle GraalVM Native Image and JDK (Java Development Kit).
GraalVM is a high-performance JDK distribution that accelerates Java workloads. GraalVM Native Image ahead-of-time compilation builds your Java application into a native executable that is small, starts fast, and uses less memory and CPU. Leading Java microservices frameworks such as Spring Boot, Micronaut, Quarkus and Helidon support GraalVM Native Image.
Oracle GraalVM is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
Cloud Shell is a free-to-use browser-based terminal accessible from the Oracle Cloud Console. It provides access to a Linux shell with preinstalled developer tools and a pre-authenticated OCI CLI. You can use the shell to interact with OCI resources, follow labs and tutorials, and quickly run utility commands.
Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you don’t have to install and configure a development machine to get started.
-
List the installed JDKs:
csruntimectl java list
The output should be similar to:
graalvmjdk-17 /usr/lib64/graalvm/graalvm-java17 * oraclejdk-11 /usr/java/jdk-11.0.17 oraclejdk-1.8 /usr/lib/jvm/jdk-1.8-oracle-x64
-
Select GraalVM as the current JDK:
csruntimectl java set graalvmjdk-17
The output should be similar to:
The current managed java version is set to graalvmjdk-17.
-
Git clone this example.
git init graalvm-native-oci-cloud-shell cd graalvm-native-oci-cloud-shell git remote add origin https://github.com/graalvm/graalvm-demos.git git config core.sparsecheckout true echo "clouds/native-oci-cloud-shell/*">>.git/info/sparse-checkout git pull --depth=1 origin master cd clouds/native-oci-cloud-shell
-
[OPTIONAL] Confirm software version and environment variables.
-
Build a JAR file for the example app.
./mvnw clean package
-
Run the JAR:
java -jar target/my-app-1.0-SNAPSHOT.jar
The output should be similar to:
Hello World!
Use GraalVM Native Image to produce a native executable.
Option 1: Quick Build enabled
You will notice the Quick Build
mode reduces the time required to generate a native executable, making it convenient to use Native Image builds in a typical development cycle (edit, compile, test, and debug). The Quick Build
mode is recommended for development purposes only.
-
To enable
Quick Build
, open pom.xml in a text editor such as Nano and uncomment the line shown:<quickBuild>true</quickBuild>
-
Use the Native Image maven plugin to create a native executable:
./mvnw clean -Pnative -DskipTests package
-
Run the native executable using:
./target/my-app
The output should be similar to:
Hello World!
Option 2: Quick Build disabled
-
To disable
Quick Build
, open pom.xml in a text editor such as Nano and comment the line shown:<!-- <quickBuild>true</quickBuild> -->
-
Use the Native Image maven plugin to create a native executable:
./mvnw clean -Pnative -DskipTests package
-
Run the native executable using:
./target/my-app
The output should be similar to:
Hello World!
Learn how to start using Oracle GraalVM with other OCI services at docs.oracle.com.