Oracle GraalVM in OCI Cloud Shell
This guide shows you how to get started with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell.
OCI Cloud Shell is a browser-based terminal accessible from the Oracle Cloud Console. It provides access to a Linux shell with a preauthenticated OCI Command Line Interface (CLI), preinstalled developer tools, and comes with 5GB of storage.
Oracle GraalVM for JDK 17 is preinstalled in Cloud Shell, so you do not have to install and configure a development machine.
Note: Oracle GraalVM license and support are included in the Oracle Cloud Infrastructure subscription at no additional cost.
Steps to Use Oracle GraalVM in Cloud Shell
Cloud Shell has several preinstalled JDKs, including Oracle GraalVM JDK.
- List the installed JDKs using the
csruntimectl java list
command.csruntimectl java list
The output lists the JDKs preinstalled in Cloud Shell: Oracle GraalVM for JDK 17, Oracle JDK 11, and Oracle JDK 8. The JDK marked with an asterisk is the current JDK.
- Select Oracle GraalVM for JDK 17 as the current JDK:
csruntimectl java set graalvmjdk-17
You will see the confirmation message printed: “The current managed java version is set to graalvmjdk-17”.
- Now confirm the values of the environment variables
PATH
andJAVA_HOME
, and the versions ofjava
and thenative-image
tool:echo $JAVA_HOME
echo $PATH
java -version
native-image --version
You are all set to run Java applications using Oracle GraalVM JDK in Cloud Shell.
Run a Java Application
The example is a minimal REST-based application, built on top of Spring Boot using Maven. The pom.xml file was generated using Spring Initializr with Spring Native Tools added as a feature. The Spring AOT plugin performs ahead-of-time transformations of a Spring application into a native executable.
- Clone the demos repository and change to the application root directory:
git clone https://github.com/graalvm/graalvm-demos.git cd graalvm-demos/spring-native-image
- Build the application with Maven (Apache Maven is also preinstalled in Cloud Shell):
mvn clean package
This will generate a runnable JAR file that contains all of the application’s dependencies as well as a correctly configured
MANIFEST
file. - Run the Java application:
java -jar ./target/benchmark-jibber-0.0.1-SNAPSHOT.jar &
Call its REST endpoint:
curl http://localhost:8080/jibber
You should see some nonsense verse printed.
Bring the application to the foreground:
fg
Stop the application by pressing Ctrl+c.
- Next, build a native executable for this Spring Boot application using the
native
Maven profile.mvn -Pnative native:compile
This will generate a native executable for Linux in the target directory, named benchmark-jibber.
- Run the native executable, using the following command:
./target/benchmark-jibber &
Call its endpoint to test:
curl http://localhost:8080/jibber
Again, you should see some nonsense verse printed.
Bring the application to the foreground:
fg
Stop the application by pressing Ctrl+c.
Congratulations! You have successfully used Oracle GraalVM JDK with Native Image to build and test a Spring Boot REST application in Cloud Shell.
Thus, you can use Oracle GraalVM in OCI Cloud Shell to build and test simple Java applications with Micronaut, Spring, and other microservice frameworks.