views:

96

answers:

1

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.

+4  A: 

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.

Michał Marczyk