Frage

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.

War es hilfreich?

Lösung

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

=> (add-dependencies
      :coordinates '[[incanter "1.2.3"]]
      :repositories (merge cemerick.pomegranate.aether/maven-central
                           {"clojars" "http://clojars.org/repo"}))

That said, you do have to have pomegranate itself in your initial classpath before it can be used.

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top