Compile clojure source into class (AOT) from command line (without using lein)

I am trying to compile the clojure source file into a class file and only run it using the command line, without lein or (possibly) an answer.

I have core.clj in a directory src/hello.

.
└── src
    └── hello
        └── core.clj

This is the source code.

(ns hello.core)
(defn -main
  "This should be pretty simple."
  []
  (println "Hello, World!"))

using (compile)in REPL.

From the hint on this site ( http://clojure.org/compilation ) I tried to get the class file from REPL.

I started REPL with lein replin the src directory and then tried to compile to get an error message.

user=> (compile 'hello.core)

CompilerException java.io.IOException: No such file or directory, compiling:(hello/core.clj:1:1)  

Command line

clojure.clj .class/.jar clojure, , clojure REPL.

., .

> java -cp .:<PATH>/clojure-1.6.0.jar -Dclojure.compile.path=build clojure.lang.Compile src/hello/core.clj 
Compiling src/hello/core.clj to build
Exception in thread "main" java.io.FileNotFoundException: Could not locate 
hello/core/clj__init.class or hello/core/clj.clj on classpath: 
at clojure.lang.RT.load(RT.java:443)
at clojure.lang.RT.load(RT.java:411) 
...

, :

  • clojure / REPL?
  • Java? java -cp .:CLOJURE_JAR main?
+3
1

REPL .

java -cp .:<PATH>/clojure-1.6.0.jar:./src clojure.main

*compile-path* (set! *compile-path* "build").

, .

user=> (compile 'hello.core)
hello.core

:

  • CP .
  • - , .

.

clojure> java -cp .:<PATH>/clojure-1.6.0.jar:./src -Dclojure.compile.path=build clojure.lang.Compile hello.core
Compiling hello.core to build

, .

clojure> java -cp .:<PATH>/clojure-1.6.0.jar:./build hello.core
Hello, World!

+2

All Articles