Import and run things in one off Clojure script
I'm new to Clojure and I've been following the tutorial here: http://devcenter.heroku.com/articles/clojure-web-application
So I've been running my apps with foreman start
and then testing small Clojure scripts with lein repl
.
However running sequences of interactions in the REPL
is time-consuming and frustrating; I'd like to put all the interacti开发者_如何学运维ons in lein repl
in a one-off script that I can run all the way through.
The following two lines work when run from lein repl
(after calling, for example, lein deps
with a project.clj
file), but not when I put them in a file called interactions.clj
and try running the file with clj interactions.clj
.
(use 'clojure.contrib.http.agent)
(string (http-agent "http://jsonip.com/"))
What do I need to do to be able to run those two lines (and more) from a one-off script?
I tried using lein run interactions.clj
, checking the instructions on importing things here (and trying out twenty different versions of ns, :use, :require and '), and lein oneoff interactions.clj
with no success. It shouldn't be that hard to do this, right?
This isn't exactly what you're asking for, but I usually create a runnable jar file as explained here: http://zef.me/2470/building-clojure-projects-with-leiningen.
I want
java -cp /path/to/clojure-1.X.X.jar:path/to/other/deps clojure.main -i /path/to/scratchfile.clj
精彩评论