Fork me on GitHub
#graalvm
<
2023-03-03
>
Chase18:03:08

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

borkdude18:03:17

Yes. Just set GRAALVM_HOME and JAVA_HOME for your project

2
borkdude18:03:48

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

borkdude18:03:11

If the CLI app is little, perhaps #CLX41ASCS + #C0400TZENE7 is also an idea.

Chase18:03:52

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

phronmophobic18:03:10

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

Chase18:03:55

nice. And then how do you get back?

phronmophobic18:03:32

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

👍 2
borkdude18:03:07

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

borkdude18:03:58

> 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

phronmophobic18:03:50

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

Chase18:03:25

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

Chase19:03:17

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

borkdude19:03:12

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.

Chase19:03:11

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

borkdude19:03:56

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)))

borkdude19:03:42

reader conditionals are also supported:

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

lread21:03:35

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

👍 2