This part shows how you can get started quickly with GraalVM Enterprise Edition in Oracle Cloud Infrastructure (OCI) Code Editor using the Spring Boot 3 microservice example.
GraalVM Enterprise Edition is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
Code Editor enables you to edit and deploy code directly from the Oracle Cloud Console. You can develop applications, service workflows, and scripts entirely from a browser. This makes it easy to rapidly prototype cloud solutions, try new services, and accomplish quick coding tasks.
GraalVM Enterprise JDK 17 and Native Image are preinstalled in Cloud Shell, so you don’t have to install and configure a development machine to get started. Code Editor's integration with Cloud Shell gives you direct access to GraalVM Enterprise JDK 17 and Native Image.
-
Open a
New Terminal
in Code Editor. Use this Terminal window to run the commands shown in this sample.
-
List the installed JDKs:
csruntimectl java list
The output should be similar to (versions may vary):
graalvmeejdk-17 /usr/lib64/graalvm/graalvm22-ee-java17 * oraclejdk-1.8 /usr/java/jdk1.8.0_351-amd64 oraclejdk-11 /usr/java/jdk-11.0.17
-
Select GraalVM as the current JDK:
csruntimectl java set graalvmeejdk-17
The output should be similar to:
The current managed java version is set to graalvmeejdk-17.
This step is optional - Check software version and environment variables
-
Git clone this example.
git init graalvmee-spring-native-image cd graalvmee-spring-native-image git remote add origin https://github.com/graalvm/graalvm-demos.git git config core.sparsecheckout true echo "spring-native-image/*">>.git/info/sparse-checkout git pull --depth=1 origin master cd spring-native-image
-
Build a JAR file for the example app.
mvn clean package
-
Run the app JAR in the background.
java -jar ./target/benchmark-jibber-0.0.1-SNAPSHOT.jar &
-
Test the app JAR.
curl http://localhost:8080/jibber
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
... And, as in uffish thought he stood, The Jabberwock, my beamish boy!<br/> ’Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And burbled as it came!<br/> He left it dead, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.<br/> Beware the Jubjub bird, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And burbled as it came!<br/> Beware the Jabberwock, my beamish boy!<br/> Beware the Jubjub bird, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.<br/> ’Twas brillig, and with its head He went galumphing back.<br/> And, as in uffish thought he stood, The Jabberwock, my son!<br/> Come to my arms, my son!<br/> ’Twas brillig, and shun The frumious Bandersnatch!<br/>
-
Bring the running app JAR in the foreground
fg
-
Once the app is running in the foreground, press CTRL+C to stop it.
Now build a native executable for your Spring Boot microservice using GraalVM Enterprise Native Image.
-
Build the app native executable
mvn -Pnative native:compile
This will create a binary executable
target/benchmark-jibber
. -
Run the app native executable in the background
./target/benchmark-jibber &
-
Test the app native executable
curl http://localhost:8080/jibber
It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
... The Jabberwock, my beamish boy!<br/> Beware the Jubjub bird, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.<br/> Beware the Jubjub bird, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And burbled as it came!<br/> Beware the Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And the mome raths outgrabe.<br/> He left it dead, and shun The frumious Bandersnatch!<br/> He left it dead, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.<br/> ’Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And burbled as it came!<br/> ’Twas brillig, and with its head He went galumphing back.<br/> Come to my arms, my son!<br/> Beware the Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And burbled as it came!<br/>
-
Bring the running app native executable in the foreground
fg
-
Once the app is running in the foreground, press CTRL+C to stop it.