I've created file "hello.clj"
(ns clojure.examples.hello (:gen-class)) (defn -main [greetee] (println (str "Hello " greetee "!")))
and try to compile
clojurec hello.clj
But I got this error
Exception in thread "main" java.io.FileNotFoundException: Could not locate hello/clj__init.class or hello/clj.clj on classpath: at clojure.lang.RT.load(RT.java:398) at clojure.lang.RT.load(RT.java:367) at clojure.core$load__5058$fn__5061.invoke(core.clj:3734) at clojure.core$load__5058.doInvoke(core.clj:3733) at clojure.lang.RestFn.invoke(RestFn.java:413) at clojure.core$load_one__5010.invoke(core.clj:3578) at clojure.core$compile__5065$fn__5067.invoke(core.clj:3744) at clojure.core$compile__5065.invoke(core.clj:3743) at clojure.lang.Var.invoke(Var.java:346) at clojure.lang.Compile.main(Compile.java:56)
I try also to put this in the file and run clojore hello.clj
(compile 'clojure.examples.hello)
But got the same error.
The Clojure compiler produces Java byte code, which is typically then JIT-compiled to native code by the JVM.
Clojure compiles all code you load on-the-fly into JVM bytecode, but sometimes it is advantageous to compile ahead-of-time (AOT). Some reasons to use AOT compilation are: To deliver your application without source. To speed up application startup. To generate named classes for use by Java.
The generated class automatically defines all of the non-private methods of its superclasses/interfaces. This parameter can be used to specify the signatures of additional methods of the generated class.
A namespace called clojure.examples.hello
needs to reside in a file called hello.clj
in a directory $CPDIR/clojure/examples
, where $CPDIR
is a directory included in the JVM's classpath.
In general, trying to set the classpath and issue the compilation command by hand makes little sense. Use Leiningen instead; the README has a pretty thorough explanation of what you'll need to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With