Is it possible to add new stuff to the classpath (e.g. editing project.clj and running lein deps
) and then importing it to an existing Clojure session?
This is, without having to disconnect and then connect again.
Is it possible to add new stuff to the classpath (e.g. editing project.clj and running lein deps
) and then importing it to an existing Clojure session?
This is, without having to disconnect and then connect again.
I'm assuming by clojure session you mean a REPL as started by lein repl
.
The short answer to your question is No - you can't do it.
The JVM supports Classloaders to provide this dynamic loading functionality and clojure makes use of these to suporrt dynamic class definitions with deftype
gen-class
etc.
Adding new 3rd party classes (presumably a new library jar) to the classpath would be fearsomely complicated when you consider that you'd have to unwind and re-construct the classloaders already in use.
See this question for more details on clojure's classloading
You can use pomegranate to download new libraries and add them to your classpath at runtime. It won't read directly from your project.clj, but does use a compatible syntax (using the Aether library which Leiningen 2 uses for its own dependency resolution).
Usage looks like so (quoting the README's example):
That said, you do have to have pomegranate itself in your initial classpath before it can be used.