simple tool for compiling Clojure .clj into .class

2019-02-24 00:47发布

问题:

I've found two ways of compiling Clojure *.clj files into *.class files, and while they both work, I have some gripes with both of them.

The first one uses a REPL and so cannot be automated (or can it?)

The second one uses lein. To be frank I don't see why I should use a dependency management tool for something that should be part of the core tool-chain of the language. But in any case, using lein soon forces you to use a local Maven repository if your Clojure code needs to access local jars (which is highly likely).

Is there a better way to generate *.class or *.jar files from Clojure code that involves only core Clojure tools and that can be employed in a scripted, non-interactive way?

回答1:

Clojure provides clojure.core.Compile, which can be used to compile Clojure code from the command-line.

java -Dclojure.compile.path=<targetdir> -cp <targetdir>;clojure.jar <list of namespaces>

For an example of how to use this from ant, look at the compile-clojure task in Clojure's own build.xml file.



回答2:

clojure.core/compile can be automated via Clojure