GraalVM Enterprise in OCI Cloud Shell
This guide shows you how to get started with GraalVM Enterprise Edition 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 pre-authenticated OCI Command Line Interface (CLI), pre-installed developer tools, and comes with 5GB of storage.
GraalVM Enterprise JDK 17 and Native Image are pre-installed in Cloud Shell.
Note: GraalVM Enterprise is available on Oracle Cloud Infrastructure at no additional cost.
Steps to Use GraalVM Enterprise in Cloud Shell
Cloud Shell has several pre-installed JDKs, including GraalVM Enterprise JDK.
-
List the installed JDKs using the
csruntimectl java listcommand. You should see the following output:csruntimectl java listThe output lists the JDKs preinstalled in Cloud Shell - GraalVM JDK for Java 17, Oracle JDK for Java 11, and Oracle JDK for Java 8. The JDK marked with an asterisk is the current JDK.
-
Select GraalVM JDK for Java 17 as the current JDK:
csruntimectl java set graalvmeejdk-17You will see the confirmation message printed
The current managed java version is set to graalvmeejdk-17. -
Now confirm the values of the environment variables
PATHandJAVA_HOME, and the version ofjava, thenative-imagegenerator:echo $JAVA_HOMEecho $PATHjava -versionnative-image --version
You are all set to run Java applications using GraalVM Enterprise JDK in Cloud Shell.
Run a Java Application
The example that you will run 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.gitcd graalvm-demos/spring-native-image -
Build the application with Maven (Apache Maven is also pre-installed in Cloud Shell):
mvn clean packageThis will generate a runnable JAR file that contains all of the application’s dependencies as well as a correctly configured
MANIFESTfile. -
Run the Java application:
java -jar ./target/benchmark-jibber-0.0.1-SNAPSHOT.jar &Call the REST endpoint:
curl http://localhost:8080/jibberYou should see some nonsense verse printed.
Bring the application to the foreground:
fgTerminate the application by pressing Ctrl+C.
-
Next build a native executable for this Spring Boot application using the
nativeMaven profile.mvn -Pnative native:compileThis 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 the endpoint to test:
curl http://localhost:8080/jibberAgain, you should see some nonsense verse printed.
Bring the application to the foreground:
fgTerminate the application by pressing Ctrl+C.
Congratulations! You have successfully used GraalVM Enterprise JDK and Native Image to build and test a Spring Boot REST application in Cloud Shell.
Thus, you can easily use GraalVM Enterprise in OCI Cloud Shell to build and test simple Java applications with Micronaut, Spring, and other microservice frameworks.