开发者

Setting CLASSPATH for Clojure project

I have a plain project structure:

Base Dir
   src ;; Pile of Clojure files
   lib ;; Jar files

To export the classpath: $ export CLASSPATH=$CLASSPATH:src:lib/*

Trying to run a Clojure file: java -cp $CLASSPATH -jar lib/clojure.jar src/wizard-game.clj

But I 开发者_开发百科got:

Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/contrib/trace_init.class or clojure/contrib/trace.clj on classpath:

Caused by: java.io.FileNotFoundException: Could not locate clojure/contrib/trace_init.class or clojure/contrib/trace.clj on classpath:

Ok, this is a classpath issue but what/where I'm doing wrong?

Is there a better way to try to run it?

UPDATE:

I tried this command:

java -classpath $CLASSPATH clojure.main src/wizard-game.clj

It runs ok now.


From the java man pages regarding the -jar option:

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

So that's a bit of a bummer, but the good news is that you can get around this by using a different launching syntax (referenced at clojure.org):

java -cp $CLASSPATH clojure.main src/wizard-game.clj

Alternatively, use a tool like Leiningen to manage your project's classpath and dependencies for you!


This is a response to your "How to run a standalone Clojure file in Lein?" you should look at into lein run. I'm not sure the current state but there was a standalone Lein plugin and now there is at least some (maybe all) of the functionality build into lein by default.

Try running a lein help run at the command line for a quick introduction.

Standalone lein-run project. Documentation may be useful. Not 100% sure if it matches up with the built-in lein run but I know from my own usage at least some of it does.

https://github.com/sids/lein-run

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜