Fork me on GitHub
#beginners
<
2021-11-12
>
João Galrito02:11:45

Hi - I have a Java project where I would like to load (and reload) .clj files at runtime. The folder where these files are located can also change at runtime, so I assume I need a ClassLoader

seancorfield05:11:12

For the folder changing at runtime, yes, you're going to need to construct a classloader with that folder on it, but as far as reloading Clojure files: if you use Clojure's Java API, you can easily get a handle on require and use it with :reload or :reload-all to get Clojure to recompile namespaces from disk.

seancorfield05:11:30

https://clojure.org/reference/java_interop#_calling_clojure_from_java has some examples of using the Java API to dynamically require a namespace.

seancorfield05:11:02

Oh, any dependencies your Clojure code needs will have to be added to your classpath somehow too. For Clojure itself, you can just make it a dependency of the Java project -- and if you know your Clojure code's dependencies ahead of time, you can also add those to your Java project, but otherwise you'll need something to resolve and fetch those deps for you.

seancorfield05:11:56

When I was doing that sort of integration into a legacy (non-Clojure) app, I had the program run clojure -Spath and parsed the output to add JARs to the classpath (the act of running clojure -Spath resolves and downloads deps from a deps.edn file -- I was working with actual Clojure projects and calling into them from legacy code). You could always use -Sdeps to provide extra dependencies via the command-line instead of needing deps.edn. And of course that does assume that you'll have the Clojure CLI installed wherever this Java project might run -- which may not be viable for you.

João Galrito12:11:36

Thank you very much, I got it more or less working yesterday, but the dependencies insight is helpful

João Galrito12:11:47

I'll probably just include the dependencies beforehand

João Galrito12:11:57

For my use case I think that works

Pagoda 5B08:11:02

Hello, request for help from anyone using calva on vscode, and has projects not related to clojure... When I fire up the editor (I have multiple projects open), each window starts the calva extension, usually creating local .lsp files too. I would like to avoid this when the project/workspace I'm opening is not related to clojure in any way: is there some configuration to do that? I have to clean up the project from calva conf files to avoid unwillingly add them to the git projects... Thanks for any help

pez14:11:24

Calva shouldn’t actually activate in a project not related to Clojure… Anyway, I have this in my ~/.gitignore

**/.clj-kondo/.cache/
**/.lsp/.cache/
**/.calva/output-window/output.calva-repl
**/.portal/vs-code.edn
So then these file don’t litter down the git repos at least.

pez14:11:48

There is a #calva channel as well, btw. 😃

thanks2 1
sheluchin12:11:38

Is there a go-to library that Clojurians use to manage scheduled tasks? I'm looking for a Clojure equivalent of https://docs.celeryproject.org/en/stable/, although maybe a bit more lightweight 🙂

dharrigan12:11:34

Are you meaning, cron-like functionality?

sheluchin12:11:54

Yeah, more or less.

1
dharrigan12:11:43

I've had good success with

dharrigan12:11:49

there are lots of others out there too

dharrigan13:11:32

and so on...

sheluchin13:11:43

Thanks very much.

dharrigan13:11:01

You're most welcome.

shidima12:11:19

I'm writing data to a firebase db with cljs, but I get a warning about type inference:

Cannot infer target type in expression (. snapshot val)
Does any one have a hint as to what I should do to resolve this?

aqua16:11:17

You need to use a type hint: https://clojurescript.org/guides/externs#externs-inference Googling the error gives this page