I'm running Debian Wheezy, openjdk-7-jre, clojure 1.4.0 and leiningen-1.7.1, all installed from official repo.
So I ran
lein new hello
cd hello
lein run -m hello.core
and saw an error:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: hello.core
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.RT.classForName(RT.java:2017)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:225)
at user$eval35.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: hello.core
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at clojure.lang.RT.classForName(RT.java:2013)
... 21 more
I never written anything before in Java so this is very cryptic for me. I tried to add
:main hello.core
to my project.clj file and then just
lein run
but it didn't helped me.
To run the main
function, make sure that hello.core
contains -main
method like this:
(ns hello.core)
(defn -main
[& args]
(println "Hello, World!"))
and you can run it with the -m
flag: lein run -m hello.core
.
Or you can run arbitrary function if you specify its name:
(ns hello.core)
(defn my-run
[& args]
(println "Hello, World! from Run"))
And call it with the namespace/function_name as an argument:
lein run -m hello.core/my-run
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