5

How can I run a clojure file/script, which uses clojure-contrib, from the command line? My (winodws) machine has clojure-1.2.1.jar and clojure-contrib-1.2.0.jar on the classpath. Note: I can start the REPL with: java clojure.mainand I can execute *.clj files that DO NOT use clojure-contrib with: java clojure.main file-name.clj

tmore
  • 693
  • 1
  • 6
  • 6
  • If you are sure that clojure-contrib-1.2.0.jar is on the classpath, I suggest verifying that the jar is a valid jar file, e.g. using this command: jar tvf clojure-contrib-1.2.0.jar. (Assumes the jar is in the current directory.) – user100464 Jul 13 '11 at 22:22
  • if you could give us feedback about our answers, we might be able to help you further – bmillare Jul 20 '11 at 22:04

3 Answers3

3

You need to add the clojure-contrib jar to the classpath. Since you are using windows, you add multiple classpaths by separating the entries with semicolons.

 java -cp clojure-1.2.1.jar;clojure-contrib-1.2.0.jar clojure.main file-name.clj

The above code should enable you to run your file-name.clj script which depends on clojure-contrib.

bmillare
  • 4,183
  • 2
  • 23
  • 42
2

This line will run a clojure script "hello-world.clj". It first adds the clojure jar to the class path first and then will execute the file.

java -cp clojure.jar clojure.main hello-world.clj
kmdent
  • 1,577
  • 16
  • 32
  • 2
    Downvoting. The OP wanted to know how to run a clojure file/script that uses clojure-contrib. Your example will not do that. – user100464 Jul 13 '11 at 22:19
  • Upvoting because the reason for downvoting was silly. You've got to leave *something* as an exercise to the reader. – Rayne Jul 14 '11 at 03:08
  • 3
    A careful re-reading of the OP's question will reveal that the OP is capable of running a script that depends only on clojure.core. An answer stating, "Clojure depends on Java" would also leave something to the imagination but would also be deserving of a downvote because it, too, would do nothing to contribute to the OP's question. – user100464 Jul 14 '11 at 13:18
  • 1
    @rayne I don't see it as self evident that "You've got to leave something as an exercise to the reader." Certainly answering the question shouldn't. – bukzor Feb 11 '13 at 04:40
0

for those used to text editor + lots of shell work

lein run isn't bad and lein projects can help you organize deps and other proj-specific

han
  • 175
  • 2