;; How to pull in a library at runtime ;; dependencies [[org.clojure/clojure "1.4.0"] ;; [com.cemerick/pomegranate "0.0.13"]] ;; When working at the REPL, it's often a pain to stop clojure, add a library to your dependencies, and restart. ;; Behold the solution, due to Chas Emerick (on whom blessings) (require 'cemerick.pomegranate) ;; We don't, I think, even need to download the library. Pomegranate will go off and get it if it needs to: (cemerick.pomegranate/add-dependencies :coordinates '[[ring "1.1.7"]] :repositories {"clojars" "http://clojars.org/repo" } ) ;; It takes a while, but once it's done : (require 'ring.adapter.jetty) (defonce server (ring.adapter.jetty/run-jetty (fn[x]{:body"<h1>yo</h1>"}) {:port 8080 :join? false})) ;; And it works! ;; I am told that there are reasons not to use this in production ;; code, only at the REPL, which is a terrible shame, since otherwise ;; programs could specify their own dependencies and versions rather ;; than having to exile them to a separate file. ;; Still, this is a huge time-saver, and takes a lot of the pain out of trying a new library.
Blog Archive
-
▼
2013
(52)
-
▼
February
(10)
- Rerum Cognoscere Causas
- Clojure's Reader is Unsafe
- Linear Congruential Random Number Generators
- Packing and Unpacking Numbers : Deterministic Rand...
- Clojure Emacs Eval Paste Keyboard Macros / Generat...
- Mathematics as an Experimental Science
- A Naive Bayesian Classifier
- Clojure is Fast / Is Clojure Still Fast? / Clojure...
- FOR vs MAP
- Runtime Require: Downloading a New Dependency and ...
-
▼
February
(10)
Search This Blog
Saturday, February 2, 2013
Runtime Require: Downloading a New Dependency and Adding it to the Classpath at Runtime with Pomegranate
Everything that I don't like about Clojure is really something I don't like about the JVM. Here is one tiny blow for freedom:
Subscribe to:
Post Comments (Atom)
I have no idea what the implicit complaint has to do with the JVM.
ReplyDeleteFixed classpath on startup so you can't load a new library. Obviously this isn't actually true, since you can, but it doesn't make it easy. Compare 'import lib' in python.
DeleteFrom my ~/.lein/init.clj: http://pastebin.com/jU59t8vQ
ReplyDeleteMarek