graalvm 2023-03-03

I want to explore using GraalVM to build out a little CLI app and am curious about having several JVM's on my system. I'm using Temurin-17.0 right now and would like to keep that as my default. Can I install Graal, use it to bundle up my app, then get back to Temurin pretty easily or is this a big hassle? I'm using Debian

Yes. Just set GRAALVM_HOME and JAVA_HOME for your project

➕ 1

I usually just download GraalVM in my Downloads folder and write a script that takes into account the above GRAALVM_HOME env var

If the CLI app is little, perhaps #babashka + #babashka-bbin is also an idea.

It is small. Does babashka work with clj-http? For some reason I was having issues with http-kit

I have the following in my .bash_profile

function graalvm() {
    export GRAALVM_HOME=/Users/adrian/workspace/graalvm/graalvm-ce-java19-22.3.1/Contents/Home
    export JAVA_HOME="$GRAALVM_HOME"
    export PATH=$JAVA_HOME/bin:$PATH
    java -version
}
You can switch to using the graalvm jvm just by typing:
$ graalvm

nice. And then how do you get back?

You could set it up to restore, but I just close that terminal and start a new one 😄

👍 1

Also, I almost never find the need to "get back" since GraalVM works perfectly fine as a normal JVM as well

> It is small. Does babashka work with clj-http? For some reason I was having issues with http-kit No, but it has https://github.com/babashka/http-client which is built on the java.net.http package

Compiling native-image can be fairly slow though. Because of that, bb and friends is a great place to start since it's precompiled.

Yeah I'm going to give bb a shot since I've wanted to get some experience with it anyways. That built in http-client looks perfect for my simple needs

And clojure.data.json works with bb too? Sorry this got so derailed

in bb, cheshire.core is the built-in json library. clojure.data.json works from source, but it's slow if you have big payloads since it's interpreted.

I can try with cheshire , it's a small 40 line program

you can do it like this, if you want to use clojure.data.json:

(defmacro if-bb [then else]
  (if (System/getProperty "babashka.version") then else))

(defn parse-json [s]
  (if-bb
    ((requiring-resolve 'cheshire.core/parse-json) ...) s)
    ((requiring-resolve 'clojure.data.json/read-str) s)))

reader conditionals are also supported:

#?(:bb ... :clj ...)

I personally use https://sdkman.io/ to switch between JDKs. Works nicely for me.

👍 1