cider

winsome 2025-09-26T05:48:24.593329Z

How does nREPL choose its JVM? I have 24.0.1:

$ java -version
openjdk version "24.0.1" 2025-04-15
OpenJDK Runtime Environment GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01)
OpenJDK 64-Bit Server VM GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01, mixed mode, sharing)
But when I start up an nREPL server for my project:
JAVA_HOME=$(which java) clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version "0.57.0"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
It's picking up some other JDK it found on my system somehow:
;; Connected to nREPL server - 
;; CIDER 1.15.1 (Cogne), nREPL 1.3.1
;; Clojure 1.12.1, Java 21.0.7
I would very much like to use a new JVM.

borkdude 2025-10-04T14:46:34.748779Z

> Depending on the OS, there are specialized tools to resolve java home. For example, on MacOS, it is /usr/libexec/java_home

borkdude 2025-10-04T14:47:15.659249Z

somehow on my system that doesn't work together. I installed Java with sdkman.

borkdude@MBP25-2 ~/dev/eucalypt (games) $ echo $JAVA_HOME
/Users/borkdude/.sdkman/candidates/java/current
borkdude@MBP25-2 ~/dev/eucalypt (games) $ /usr/libexec/java_home
The operation couldn't be completed. Unable to locate a Java Runtime.
Please visit  for information on installing Java.

oyakushev 2025-10-04T14:49:50.088699Z

SDKMan surely appropriates all Java version management, so it is understandable.

borkdude 2025-10-04T14:51:42.608269Z

> > I recently stumbed on a script that only called /usr/libexec/java_home`

borkdude 2025-10-04T14:52:27.687879Z

eeks, I can't get rid of this quoting thing. sorry. anyway. the script ignored JAVA_HOME but just called that command. I had to tweak it. Just pointing this out that JAVA_HOME should probably be preferred over anything else?

oyakushev 2025-10-04T17:33:55.180299Z

Well, I would prefer JAVA_HOME when dealing with somebody's else setups, sure

winsome 2025-09-26T07:00:53.301399Z

> "/nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6/lib/openjdk"

winsome 2025-09-26T07:01:23.231419Z

Back to 21.0.7.

oyakushev 2025-09-26T07:03:29.084439Z

Sorry mate, I'm out of ideas. Try asking in #clojure, there must be Nix folks that've dealt with this before.

winsome 2025-09-26T07:04:12.578329Z

Hold on, I was getting too sleepy - it's right there in the docs that JAVA_CMD is higher precedence, let me try that.

winsome 2025-09-26T07:04:39.778819Z

JAVA_CMD=/nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/bin/java clojure
Clojure 1.12.0
user=> (System/getProperty "java.version")
"24.0.1"
It works!

👍 1
oyakushev 2025-09-26T07:05:01.410699Z

But it wasn't set before, you say?

winsome 2025-09-26T07:05:56.923599Z

It wasn't, I'm going to have to add that to my workflow. I honestly don't understand why the PATH java wasn't working, but I won't complain now : )

winsome 2025-09-26T07:06:04.961229Z

Thank you for working with me :D

oyakushev 2025-09-26T07:06:18.307039Z

No problem, glad it worked

🙌 1
winsome 2025-09-26T07:06:37.969029Z

Good night 👋

Kirill Chernyshov 2025-09-26T06:12:17.199069Z

I think which java gives you a path to java binary, but JAVA_HOME should point to the dir above.

☝️ 1
oyakushev 2025-09-26T06:14:28.552749Z

Depending on the OS, there are specialized tools to resolve java home. For example, on MacOS, it is /usr/libexec/java_home

winsome 2025-09-26T06:19:12.596219Z

I tried doing JAVA_HOME as the directory above the java binary, but I still get Java 21.0.7 in the nREPL connection message.

winsome 2025-09-26T06:20:08.596189Z

I don't really need to change between versions at this point, so I'm just looking for the simplest possible way to get an nREPL on a recent JVM.

oyakushev 2025-09-26T06:24:46.543419Z

There is nothing nREPL specific here. You get the JDK that Clojure gets, and Clojure gets one from JAVA_HOME. Please double-check that the JAVA_HOME you set is the correct one. Show what (System/getenv "JAVA_HOME") returns.

winsome 2025-09-26T06:33:55.147429Z

This is what I did to launch it:

JAVA_HOME=/run/current-system/sw/bin clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version "0.57.0"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
Where /run/current-system/sw/bin/java is a symlink (I'm on NixOS):
lrwxrwxrwx 3 root root 70 Dec 31  1969 /run/current-system/sw/bin/java -> /nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/bin/java
But the java home from inside the repl is something else.
(System/getProperty "java.home")
;; => "/nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6/lib/openjdk"

winsome 2025-09-26T06:35:18.437329Z

And (System/getenv "JAVA_HOME") is "/run/current-system/sw/bin".

oyakushev 2025-09-26T06:37:56.105839Z

Wait

oyakushev 2025-09-26T06:38:44.609369Z

Check what's in that directory. Is it a real java binary or a symlink to another file?

oyakushev 2025-09-26T06:40:13.376159Z

Sorry, read your comment now.

oyakushev 2025-09-26T06:40:52.475219Z

You should point JAVA_HOME to the directory that contains stuff like this:

oyakushev 2025-09-26T06:41:46.026059Z

I'm not familiar with how NixOS does things, but maybe there is something there to properly resolve the correct paths to JDK installations

oyakushev 2025-09-26T06:43:23.646379Z

If not, then you can probably write a script that resolves the symlink for java, takes the directory for the real binary, then goes one level higher (there should be no bin/ at the end of JAVA_HOME). And put that script somewhere in .bashrc or what have you

winsome 2025-09-26T06:46:33.770419Z

Ok, I've given that a spin. I think I've got the corresponding directory, the java binary is now at ./bin/java relative to the JAVA_HOME path.

(System/getenv "JAVA_HOME")
"/nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/"
user> (System/getProperty "java.home")
"/nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6/lib/openjdk"
Still getting the older JVM, though.

oyakushev 2025-09-26T06:47:42.500079Z

Can you check in the terminal what's inside /nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/?

winsome 2025-09-26T06:48:34.028039Z

$ ls /nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/
bin  conf  include  jmods  legal  lib  nix-support  share

oyakushev 2025-09-26T06:48:55.559659Z

Looks legit

oyakushev 2025-09-26T06:49:02.946129Z

What what's inside /nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6?

oyakushev 2025-09-26T06:49:23.940479Z

I'm confused that the real working JDK path has lib/openjdk at the end

winsome 2025-09-26T06:50:19.665209Z

This one is a bit more complex:

ls -l /nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6
total 27
lrwxrwxrwx 5 root root 15 Dec 31  1969 bin -> lib/openjdk/bin
lrwxrwxrwx 5 root root 19 Dec 31  1969 include -> lib/openjdk/include
dr-xr-xr-x 3 root root  4 Dec 31  1969 lib
dr-xr-xr-x 2 root root  4 Dec 31  1969 nix-support
dr-xr-xr-x 2 root root  3 Dec 31  1969 share

oyakushev 2025-09-26T06:51:41.365069Z

It looks like a bit of this to me:

winsome 2025-09-26T06:51:45.391819Z

It's got some soft links, but the ./lib/openjdk path leads to the same place:

ls /nix/store/qagnl38l96xcbx17ll0v9zswhcl1nqw6-openjdk-21.0.7+6/lib/openjdk/
bin  conf  include  jmods  legal  lib  man  release

winsome 2025-09-26T06:51:59.742449Z

You're not wrong : )

😁 1
winsome 2025-09-26T06:52:30.287239Z

I don't understand what clj is doing to find the JVM, though. It's clearly not paying attention to JAVA_HOME

oyakushev 2025-09-26T06:52:46.604009Z

Wait, I think toold.deps has another place it tries to look up java version, it could be that. Let me check

oyakushev 2025-09-26T06:54:09.119089Z

https://clojure.org/reference/clojure_cli

oyakushev 2025-09-26T06:54:38.797939Z

Sent you on a wild goose chase, sorry

winsome 2025-09-26T06:55:06.429539Z

So, JAVA_CMD is not set.

oyakushev 2025-09-26T06:55:23.300829Z

In my setup, changing JAVA_HOME updates java and other JDK binaries too.

winsome 2025-09-26T06:56:11.730089Z

java on the PATH should be what which java points to, so that should be 24.0.1.

winsome 2025-09-26T06:57:14.147389Z

ll $(which java)
lrwxrwxrwx 3 root root 70 Dec 31  1969 /run/current-system/sw/bin/java -> /nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/bin/java

oyakushev 2025-09-26T06:59:00.455729Z

Try this

JAVA_HOME='/nix/store/8ca2h2dk00iwn725dr46n7zd1j18jvn8-graalvm-ce-24.0.1/lib/openjdk' clj -e '(System/getProperty "java.home")'