
SQLcl with JavaScript on macOS using GraalVM
I needed to use JavaScript capabilities in SQLcl and realized that this does not work anymore with my OpenJDK setup. Jeff Smith blogged about the background details and how he got it working. As it changed a bit, was for Windows, and I am on macOS, I decided to blog my solution. Also, note that I don’t want to mess with my main OpenJDK setup, so I used a way to type a command and switch to GraalVM.
Download GraalVM and extensions
#Download GraalVM from this page. Make sure to select your OS and architecture (ARM64 M macs).
Visit this page and check that you have the correct OS and architecture selected (macOS/aarch64 for M Macs). Then download these three extensions:
- JavaScript Runtime
- Tregex Plugin
- ICU4J Plugin
We also need the ICU4J and Tregex plugins as they are dependencies for the JavaScript plugin.
Be able to switch GraalVM
#- Unzip the GraalVM archive and move it to a location of your choice. I moved it to
/Users/phartenfeller/graalvm/graalvm-jdk-17.0.13+10.1. - Edit your
.zshrcor.bashrcfile and add the following lines:
1graal-vm() {
2 export JAVA_HOME="/Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.1.0/Contents/Home"
3 export PATH="/Users/phartenfeller/graalvm/graalvm-jdk-17.0.13+10.1/Contents/Home/bin/":$PATH
4}
5- Run
source ~/.zshrcorsource ~/.bashrcto apply the changes. - Run
graal-vmto set the environment variables. - Run
java --versionand verify that the output containsOracle GraalVM.
Test if SQLcl works
#1sql -nolog
2
3# SQLcl: Release 24.3 Production ...
4
5sql> script
6 2 ctx.write("Works\n")
7 3* /
8# Should error
9# JavaScript engine not found.
10# GraalVM with Nodejs/Javascript support is required
11Install JavaScript capabilities
#1cd /Users/phartenfeller/graalvm/graalvm-jdk-17.0.13+10.1/Contents/Home/bin
2
3# icu4j
4./gu -L install /Users/phartenfeller/Downloads/icu4j-installable-jdk-17-darwin-aarch64-23.0.6.jar
5# regex
6./gu -L install /Users/phartenfeller/Downloads/regex-installable-jdk-17-darwin-aarch64-23.0.6.jar
7# js
8./gu -L install /Users/phartenfeller/Downloads/js-installable-jdk-17-darwin-aarch64-23.0.6.jar
9Test if JS works
#1sql -nolog
2
3sql> script
4 2 ctx.write("Works\n")
5 3* /
6# Works
7Conclusion
#Now every time I want to use SQLcl with JavaScript capabilities, I can just run graal-vm and my main Java version switches to the GraalVM version that can run JavaScript. This way I can keep my main Java version for other projects and only switch when needed.
By the way. If you want to easily run a local containerized database with APEX set up in minutes, check out my project uc-local-apex-dev. I have also been busy in December with an Advent Calendar full of 24 short APEX tip videos.