Christoph's 2 Cents

A Backup for My Brain!

CloudDevOpsJavaScriptOracle DevelopementOS X (Mac)shell scripting

Configure GraalVM on Mac OS for running JavaScript in SQLcl

You may have already come across Jeff Smith’s post How to run JavaScript in Oracle SQLcl with Java 17.

To complement that post, I’ve added a few more details to get JavaScript working in SQLcl under Java 17 for Mac OS.
(Windows users see Setting up Oracle SQLcl under GraalVM 17.)

The official Documentation is a good guide, however, I did run into some dependencies issues on my Mac.

The following steps assume you already have Java 17 running on your Mac, but when you run a JavaScript in SQLcl you get:

SQL > script
  2  print('hello');
  3* /
js language engine not found
Please add js language engine to the classpath

You can also use the show java command to get details of the Java Version running. Note that this gives a lot of output, so just look at the first few lines:

SQL> show java
Java Detail
-----------
java.home= /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
java.vendor= Oracle Corporation
java.vendor.url= https://java.oracle.com/
java.version= 17.0.2

You can also check the Java installed on your computer try via a terminal command:

/usr/libexec/java_home -V
Matching Java Virtual Machines (5):
17.0.8+9.1/Contents/Home
    17.0.2 (x86_64) "Oracle Corporation" - "Java SE 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
...(output may vary)...

This shows that Java 17 is installed.

To get JavaScript to work with SQLcl, you need the GraalVM along with the JavaScript plugin.

Download the GraalVm

For Mac with the M1 processor chose the ARM64 link. For Intel Macs choose the x64 link.

Download the JavaScript plugin and the two required pendencies:

I’ll assume that the downloaded files are now in your Downloads directory.

Installation

The installation will have to be done via the Mac terminal. Open a terminal window and navigate to the Java virtural machines directory:

cd /Library/Java/JavaVirtualMachines/

Copy the GraalVm download to this directory and extract it. Make sure to use sudo with your commands.

sudo cp ~/Downloads/graalvm-jdk-17_macos-x64_bin.tar.gz .
sudo tar xvf graalvm-jdk-17_macos-x64_bin.tar.gz

Clean up the archive file

sudo rm graalvm-jdk-17_macos-x64_bin.tar.gz 

Validate that GraalVM is properly installed

/usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    17.0.8 (x86_64) "Oracle Corporation" - "Oracle GraalVM 17.0.8+9.1" /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.8+9.1/Contents/Home
...(output may vary)...

Now install the dependencies and JavaScript plugin by navigating the bin directory of Graal and running the install commands:

cd /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.8+9.1/Contents/Home/bin
sudo ./gu -L install ~/Downloads/icu4j-installable-jdk-17-darwin-amd64-23.0.1.jar
sudo ./gu -L install ~/Downloads/regex-installable-jdk-17-darwin-amd64-23.0.1.jar
sudo ./gu -L install ~/Downloads/js-installable-jdk-17-darwin-amd64-23.0.1.jar

This completes the installation. The final step is setting your JAVA_HOME to the GraalVM

export JAVA_HOME=/Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.8+9.1/Contents/Home

To persist the JAVA_HOME you can place the export command in one of your resource files like .bash_profile or .zshrc, depending on which shell you use.

Test JavaScript in SQLcl

SQL> script
  2  print('hello');
  3* /
hello
SQL>

The show java command now shows that it is running with GraalVM:

SQL> show java
Java Detail
-----------
java.home= /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.8+9.1/Contents/Home
java.vendor= Oracle Corporation
java.vendor.url= https://java.oracle.com/
java.version= 17.0.8