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.

As of version 22.2.0, 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.

  1. Login to OCI Console and launch Cloud Shell.

  2. List the installed JDKs using the csruntimectl java list command. You should see the following output:

     csruntimectl java list
    

    The output is similar to:

       graalvmeejdk-17.0.4           /usr/lib64/graalvm/graalvm22-ee-java17
     * openjdk-11.0.15               /usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.0.1.el7_9.x86_64
       openjdk-1.8.0.332             /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el7_9.x86_64
    

    The JDK marked with an asterisk is the current JDK.

  3. Select GraalVM JDK as the current JDK:

     csruntimectl java set graalvmeejdk-17.0.4
    

    You will see the confirmation message printed:

     The current managed java version is set to graalvmeejdk-17.0.4.
    
  4. Now check the version of java, the native-image generator, as well as the values of the environment variables PATH and JAVA_HOME:

     java -version
    
     java version "17.0.4" 2022-07-19 LTS   
     Java(TM) SE Runtime Environment GraalVM EE 22.2.0 (build 17.0.4+11-LTS-jvmci-22.2-b05)   
     Java HotSpot(TM) 64-Bit Server VM GraalVM EE 22.2.0 (build 17.0.4+11-LTS-jvmci-22.2-b05, mixed mode, sharing)
    
     native-image --version
        
     GraalVM 22.2.0 Java 17 EE (Java Version 17.0.4+11-LTS-jvmci-22.2-b05)
    
     echo $JAVA_HOME
        
     /usr/lib64/graalvm/graalvm22-ee-java17
    
     echo $PATH
        
     /usr/lib64/graalvm/graalvm22-ee-java17/bin/:/ggs_client/usr/bin:/home/user_xyz/.yarn/bin:/...
    

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.

  1. 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
    
  2. 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.

  3. 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.

  4. Next build a native executable for this Spring Boot application using the native Maven profile.

     export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false
        
     mvn package -Dnative
    

    This will generate a native executable for Linux in the target directory, named jibber.

  5. Run the native executable, using the following command:

     ./target/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.

Congraulations! You’ve 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 microservices frameworks.