Creating executable programs in Clojure
Until now, we have only entered snippets of code in Clojure's interactive REPL shell. As mentioned in the previous chapter, Clojure is not bundled with a standalone compiler program. To create executable programs in Clojure, you'll have to call an ordinary Clojure macro in your code that will instruct the built-in compiler to generate JVM .class
files. This macro only generates class files when Clojure compiles code and does nothing when you run code that is already compiled.
Compiling to class files without Leiningen
Let's start by creating an executable class without the build system. You'll appreciate Leiningen more when you experience the difference. Let's create this small project with a normal text editor instead of using Eclipse IDE. Create the testproject1
root directory to hold the example files, and start by creating the required subdirectories:
com
com\example
classes
Before Clojure writes class files, you'll have to generate JVM classes. One...