Fork me on GitHub

Hi! Need to set a system property for the repl process. Would like to launch the process from the UI, so need the equivalent of clj -J-Dfoo=bar. (How) can this be done from Calva?


Can it be done via the system environment? If so, there is a calva.jackInEnv setting. There is also a jackInEnv for custom jack-in/connect sequences:


Yes, but what should I put there? Whatever starts the java process needs to take this environment variable into account.

Alex Miller (Clojure team)09:07:09

Environment variables and Java system properties are different things

Alex Miller (Clojure team)09:07:31

If you can call Clojure code you can call System/setProperty


Sure. My case is that I need glass.gtk.uiScale=192dpi for reveal so I might also get away with calling it from the repl. However, (how) does Calva allow me to set parameters on the Java process? What if I need to set things that cannot be set dynamically? E.g., memory related parameters.


Calva currently has no such mechanisms for Jack-in. What you can do is to use the command Copy Jack-in Command Line (not sure about the actual name, but something like that) and edit that command line as you need. Then use that command line to start the REPL, and Calva Connect instead of Jack-in to connect Calva.


For when System/setProperty and Jack-in can be used, the custom connect sequences have a afterCLJReplJackInCode setting where you can put the calls.


There is also JAVA_OPTS which could be set with jackInEnv


Sure, but using JAVA_OPTS you still need something which sets it on the command line of the Java process, no? NP if it means I have to start the process elsewhere. Just wanted to check whether there is a "better way".


I’m not sure I understand the question correctly. The environment variable JAVA_TOOL_OPTION is supposed to be picked up by whatever spawns the java process, no? If I add this to my workspace’s settings.json:

"calva.jackInEnv": {
        "JVM_OPTS": "${env:JVM_OPTS} -Dfoo=1",
        "JAVA_TOOL_OPTIONS": "${env:JAVA_TOOL_OPTIONS} -Dbar=2 -Xmx555m -Xms66m"
Then at jack-in, I see this in the terminal:
lein update-in :dependencies conj '[nrepl,"0.8.3"]' -- update-in :plugins conj '[cider/cider-nrepl,"0.26.0"]' -- update-in '[:repl-options,:nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- repl :headless
Leiningen's classpath: :/usr/local/Cellar/leiningen/2.9.1/libexec/leiningen-2.9.1-standalone.jar
Picked up JAVA_TOOL_OPTIONS:  -Dbar=2 -Xmx555m -Xms66m
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Applying task update-in to [:dependencies conj [nrepl,"0.8.3"] -- update-in :plugins conj [cider/cider-nrepl,"0.26.0"] -- update-in [:repl-options,:nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- repl :headless]
Applying task update-in to [:plugins conj [cider/cider-nrepl,"0.26.0"] -- update-in [:repl-options,:nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- repl :headless]
Applying task update-in to [[:repl-options,:nrepl-middleware] conj ["cider.nrepl/cider-middleware"] -- repl :headless]
Applying task repl to [:headless]
Applying task javac to nil
Running javac with [@/var/folders/t5/gqxhj8pd6p9_tnvy6sbtmy480000gn/T/.leiningen-cmdline1885575088772468503.tmp]
Applying task compile to nil
All namespaces already AOT compiled.
Picked up JAVA_TOOL_OPTIONS:  -Dbar=2 -Xmx555m -Xms66m
nREPL server started on port 62564 on host - 
And at the REPL:
(System/getProperty "bar") => "2"
And, even:
(System/getProperty "foo") => "1"


@U0ETXRFEW Ah ok. I understand that leiningen processes environment variables. I am looking at a deps.edn based project. Should have probably emphasized that. Sorry.


I just happened to use Leiningen there. It should work the same with deps.edn. Have you tried it?


Like so when I try it.

clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.8.3"},cider/cider-nrepl {:mvn/version,"0.26.0"}}}'  -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
Picked up JAVA_TOOL_OPTIONS:  -Dbar=2 -Xmx555m -Xms66m
WARNING: When invoking clojure.main, use -M
Picked up JAVA_TOOL_OPTIONS:  -Dbar=2 -Xmx555m -Xms66m
nREPL server started on port 64326 on host localhost - 
And at the REPL:
(System/getProperty "bar") => "2"
However, to my surprise there is a difference with JAVA_OPTS:
(System/getProperty "foo") => nil
No idea why that would be… But since the advice from that SO thread is to not rely on JAVA_OPTS, it doesn’t really matter.


On the go. Will try when I get back. Clojure picking up JAVA_TOOL_OPTIONS is new to me. Guess it will do the trick. Thanks @U0ETXRFEW!

🙏 3
Franco Gasperino22:07:32

good afternoon. when using calva within VS code. i seem to be unable to use the "load current file and all dependencies" as i would expect. The current file (namespaces) are read and evaluated, but dependencies are not. I must open each required namespace manually and evaluate them as well. Is this a missing directive in the deps.edn?


Dependencies should be loaded with the load file command. Can you provide steps to reproduce the problem?


I mean, specifically, code that we can try out.


Are you getting errors that things aren't defined that should be, or are you not getting updates to changes made in required namespaces?

Franco Gasperino07:07:31

sorry for the delay in my response. it's the former, where expressions defined in :required expressions don't seem to be loaded by the "load current file and dependencies" command

Franco Gasperino07:07:24

if i open those files and issue the same "load current file ..." on them manually, the symbols are no longer undefined

Franco Gasperino07:07:53

so it doesn't appear as the dependency loading is transitive across files / namespaces automatically


That's really odd. If you can provide a small project where you can reproduce the issue, and the steps you take to do so, that would be helpful. A GitHub issue might be better for that.


If I have (def x 3) in the namespace foo, and I require foo in another namespace, core, then I jack in and load the file for core and eval f/x it returns 3.


I'm wondering if there's something specific to your environment or project that would make something like that not work, which is why a sample project would help us narrow down the issue.

Franco Gasperino16:07:00

ok. ill see if i can reproduce it in another project.

👍 3

Just opened an issue suggesting a new cool feature for Calva, LMK what do you think 🙂

👍 6
metal 6
clojure-lsp 3