12
votes

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.

1
Just out of curiosity, what's clojurec...? Where did you get it from? I really recommend Leiningen, though (see my answer for details). It's used very widely in the Clojure community and you should have no problem obtaining support in using it.Michał Marczyk
It's standard clojure compilator on linux system, its shell script with invoke: exec java -cp /usr/share/java/clojure.jar:"$dest_dir$extra_clas spath" -Dclojure.compile.path="$dest_dir" clojure.lang.Compile "$@"jcubic

1 Answers

6
votes

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.