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 list
command. You should see the following output:csruntimectl java list
The 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-17
You will see the confirmation message printed
The current managed java version is set to graalvmeejdk-17
. -
Now confirm the values of the environment variables
PATH
andJAVA_HOME
, and the version ofjava
, thenative-image
generator:echo $JAVA_HOME
echo $PATH
java -version
native-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.git
cd graalvm-demos/spring-native-image
-
Build the application with Maven (Apache Maven is also pre-installed 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 the REST endpoint:
curl http://localhost:8080/jibber
You should see some nonsense verse printed.
Bring the application to the foreground:
fg
Terminate 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 the endpoint to test:
curl http://localhost:8080/jibber
Again, you should see some nonsense verse printed.
Bring the application to the foreground:
fg
Terminate 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.