This guide shows you how to get started with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Code Editor.
OCI Code Editor provides a rich, in-console editing environment that enables you to edit code without having to switch between the Oracle Cloud Console and your local development environment. The Code Editor enables you to edit and deploy code for OCI services directly from the OCI Console.
Oracle GraalVM for JDK 17 is preinstalled in Cloud Shell, so you do not have to install and configure a development machine. Code Editor’s integration with Cloud Shell gives you direct access to it.
Note: Oracle GraalVM license and support are included in the Oracle Cloud Infrastructure subscription at no additional cost.
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.
csruntimectl java set graalvmjdk-17
You will see the confirmation message printed: “The current managed java version is set to graalvmjdk-17”.
PATH
and JAVA_HOME
, and the versions of java
and the native-image
tool:
echo $JAVA_HOME
echo $PATH
java -version
native-image --version
git init graalvmee-java-hello-world
cd graalvmee-java-hello-world
git remote add origin https://github.com/oracle-devrel/oci-code-editor-samples.git
git config core.sparsecheckout true
echo "java-samples/graalvmee-java-hello-world/*">>.git/info/sparse-checkout
git pull --depth=1 origin main
cd java-samples/graalvmee-java-hello-world/
You can now view/edit the sample code in Code Editor.
mvn clean package
java -jar target/my-app-1.0-SNAPSHOT.jar
It prints out “Hello World!”.
This Java application incorporates the Maven plugin for GraalVM Native Image that adds support for building native executables using Apache Maven. For testing purposes, build a native executable with the quick build mode first enabled and then disabled.
<quickBuild>true</quickBuild>
native
Maven profile:
mvn clean -Pnative -DskipTests package
This will generate a native executable for Linux in the target directory, named my-app.
./target/my-app
<!-- <quickBuild>true</quickBuild> -->
mvn clean -Pnative -DskipTests package
This will generate a native executable, my-app, in the target directory, replacing the previous one. You have probably noticed how the quick build mode reduced the time required to generate a native executable, making it easier to use Native Image in a typical development cycle (compile, test, and debug). However, the size of a generated executable is larger and peak performance is worse. The quick build mode is recommended for development purposes only.
./target/my-app
Congratulations! You have successfully built and run a native executable using Oracle GraalVM in OCI Code Editor without the need to switch between the Oracle Cloud Console and your local development environments. The Code Editor allows you to accomplish quick coding tasks and run applications directly from the OCI Console.