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
.zshrc
or.bashrc
file and add the following lines:
- Run
source ~/.zshrc
orsource ~/.bashrc
to apply the changes. - Run
graal-vm
to set the environment variables. - Run
java --version
and verify that the output containsOracle GraalVM
.
Test if SQLcl works
#Install JavaScript capabilities
#Test if JS works
#Conclusion
#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.