Reputation: 1524
Is it possible to compile clojure source without going into REPL? If a big project is there then it is not possible to compile each program manually & then make jar file of it, like if i wish to compile and get class files by some set of instructions in make software?
Upvotes: 5
Views: 2415
Reputation: 4233
For the sake of understanding how many of these systems work underneath, here is some bare minimum code to compile code without a repl.
Say you have some class generating code:
hello.clj:
(ns hello
(:gen-class
:methods [[sayHi [] String]]))
(defn -sayHi [this]
(println "hello world"))
You can build your "makefile" out of clojure code
compile.clj:
(set! *compile-path* "./")
(compile 'hello)
Then you just call your code as a script.
$ java -cp ~/dj/lib/clojure.jar:./ clojure.main compile.clj
$ ls
compile.clj hello.clj hello$loading__4505__auto__.class
hello.class hello__init.class hello$_sayHi.class
Now your code is compiled and you can access it like any other class file:
$ java -cp ~/dj/lib/clojure.jar:./ clojure.main
Clojure 1.3.0
user=> (import 'hello)
hello
user=> (.sayHi (hello.))
"hello world"
user=>
Upvotes: 8
Reputation: 106351
Yes - you can certainly compile and run Clojure code without using a REPL.
Some options to do this:
Upvotes: 4
Reputation: 91534
I have a large project using many languages and use make as the glue to start all the other components and this works quite well. You may do well to have make call maven or leiningen instead of using make to reinvent them.
If you are looking for an alternative to leiningen because it is not working for you or you simply wish to use something else, then perhaps you will like the Clojure Maven plugin
Personally I can't speak too highly of Leiningen and it is my personal choice, though there are many people in the internet and it's worth exploring the other options.
Upvotes: 3