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
You might want to start with:
lein new app hello
That should create a skeleton project setup for a stub main method.
It will also drop in a gen-class in the right place so you can use uberjar for
deployment.
Related
In the past I've use the windows installer provided at clojure.org to install clojure on my various Windows machines. Clojure 1.9 has been out for a few weeks now but still no sign of an installer for Windows or a generic Java-based install, as far as I can find.
I've tried downloading the jars from clojure.org and running
java -jar clojure.1.9.0.jar
but that just dumps stack:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at clojure.lang.RT.classForName(RT.java:2204)
at clojure.lang.RT.classForName(RT.java:2213)
at clojure.lang.RT.loadClassForName(RT.java:2232)
at clojure.lang.RT.load(RT.java:450)
at clojure.lang.RT.load(RT.java:426)
at clojure.core$load$fn__6548.invoke(core.clj:6046)
at clojure.core$load.invokeStatic(core.clj:6045)
at clojure.core$load.doInvoke(core.clj:6029)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invokeStatic(core.clj:5848)
at clojure.core$load_one.invoke(core.clj:5843)
at clojure.core$load_lib$fn__6493.invoke(core.clj:5888)
at clojure.core$load_lib.invokeStatic(core.clj:5887)
at clojure.core$load_lib.doInvoke(core.clj:5868)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$load_libs.invokeStatic(core.clj:5925)
at clojure.core$load_libs.doInvoke(core.clj:5909)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$require.invokeStatic(core.clj:5947)
at clojure.core.server$loading__6434__auto____8456.invoke(server.clj:9)
at clojure.core.server__init.load(Unknown Source)
at clojure.core.server__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at clojure.lang.RT.classForName(RT.java:2204)
at clojure.lang.RT.classForName(RT.java:2213)
at clojure.lang.RT.loadClassForName(RT.java:2232)
at clojure.lang.RT.load(RT.java:450)
at clojure.lang.RT.load(RT.java:426)
at clojure.core$load$fn__6548.invoke(core.clj:6046)
at clojure.core$load.invokeStatic(core.clj:6045)
at clojure.core$load.doInvoke(core.clj:6029)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invokeStatic(core.clj:5848)
at clojure.core$load_one.invoke(core.clj:5843)
at clojure.core$load_lib$fn__6493.invoke(core.clj:5888)
at clojure.core$load_lib.invokeStatic(core.clj:5887)
at clojure.core$load_lib.doInvoke(core.clj:5868)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$load_libs.invokeStatic(core.clj:5925)
at clojure.core$load_libs.doInvoke(core.clj:5909)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$require.invokeStatic(core.clj:5947)
at clojure.core$require.doInvoke(core.clj:5947)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:381)
at clojure.lang.RT.doInit(RT.java:487)
at clojure.lang.RT.<clinit>(RT.java:336)
at clojure.main.<clinit>(main.java:20)
Caused by: java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath.
at clojure.lang.RT.load(RT.java:463)
at clojure.lang.RT.load(RT.java:426)
at clojure.core$load$fn__6548.invoke(core.clj:6046)
at clojure.core$load.invokeStatic(core.clj:6045)
at clojure.core$load.doInvoke(core.clj:6029)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invokeStatic(core.clj:5848)
at clojure.core$load_one.invoke(core.clj:5843)
at clojure.core$load_lib$fn__6493.invoke(core.clj:5888)
at clojure.core$load_lib.invokeStatic(core.clj:5887)
at clojure.core$load_lib.doInvoke(core.clj:5868)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$load_libs.invokeStatic(core.clj:5925)
at clojure.core$load_libs.doInvoke(core.clj:5909)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:659)
at clojure.core$require.invokeStatic(core.clj:5947)
at clojure.main$loading__6434__auto____8543.invoke(main.clj:11)
at clojure.main__init.load(Unknown Source)
at clojure.main__init.<clinit>(Unknown Source)
... 55 more
and as I don't have files clojure/spec/alpha__init.class or clojure/spec/alpha.clj it appears that at the moment I'm out of luck.
So - is there a step-by-step to go from having the 1.9.0 jars to making it all run on Windows?
All suggestions welcomed.
TL;DR:
You also have to download org.clojure/spec.alpha and org.clojure/core.specs.alpha. Then start with:
java -cp clojure-1.9.0-alpha17.jar;spec.alpha-0.1.123.jar;core.specs.alpha-0.1.10.jar clojure.main
(Note, that your versions there will be different; and there will be : instad of ; for the unix family of OS).
How to find out about and fetch the other deps
With the recent change in Clojure to use dedicated artifacts for Spec in an alpha sub-namespace, it is no longer easy to start a simple REPL just with the regular jar (e.g. java -jar $CLOJURE_JAR clojure.main). So how to start it now?
As of before you are better off to do a lein new somewhere, change the org.clojure/clojure dependency to the version you like and do a lein deps :tree to fetch all that is needed and display what things org.clojure/core now depends on. E.g.
[org.clojure/clojure "1.9.0-alpha17"]
[org.clojure/core.specs.alpha "0.1.10" :exclusions [[org.clojure/clojure] [org.clojure/spec.alpha]]]
[org.clojure/spec.alpha "0.1.123" :exclusions [[org.clojure/clojure]]]
All your artifacts end up in ~/.m2/repository. So next you have to build up your classpath to call the REPL. You can now run lein with-profile uberjar cp in that dummy project to get the class path Leiningen is using. E.g.:
$ lein with-profile uberjar cp
/tmp/xxx/test:/tmp/xxx/src:/tmp/xxx/resources:/tmp/xxx/target/classes:/home/user/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/home/user/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar:/home/user/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar
# this will be `;` instead of `:` as well here for windows
Remove the test, src, and resources ones and that is, what you have to pass to -cp.
Future solution
As stated in the Getting Started the clojure CLI is not yet available for Windows.
This question already has an answer here:
Unexpected Difficulties with "Hello, World!"
(1 answer)
Closed 8 years ago.
I just installed Leiningen 2.4.3 using the install script for my Ubuntu 14.04 system. When I attempt to use lein to enter the REPL, I get a rather nasty dump to the console:
charles#charles-930X5J-910S5J-940X5J:~$ lein repl
nREPL server started on port 60889 on host 127.0.0.1 - nrepl://127.0.0.1:60889
Exception in thread "nREPL-worker-0" java.lang.NoSuchMethodError: clojure.tools.nrepl.StdOutBuffer.length()I
at clojure.tools.nrepl.middleware.session$session_out$fn__7630.doInvoke(session.clj:43)
at clojure.lang.RestFn.invoke(RestFn.java:460)
at clojure.tools.nrepl.middleware.session.proxy$java.io.Writer$ff19274a.write(Unknown Source)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at clojure.core$fn__5471.invoke(core_print.clj:191)
at clojure.lang.MultiFn.invoke(MultiFn.java:231)
at clojure.core$pr_on.invoke(core.clj:3392)
at clojure.core$pr.invoke(core.clj:3404)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$prn.doInvoke(core.clj:3437)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$println.doInvoke(core.clj:3457)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.main$repl_caught.invoke(main.clj:158)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__7569$fn__7582.invoke(interruptible_eval.clj:76)
at clojure.main$repl$fn__6634.invoke(main.clj:259)
at clojure.main$repl.doInvoke(main.clj:257)
at clojure.lang.RestFn.invoke(RestFn.java:1096)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__7569.invoke(interruptible_eval.clj:56)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:41)
at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__7610$fn__7613.invoke(interruptible_eval.clj:171)
at clojure.core$comp$fn__4192.invoke(core.clj:2402)
at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__7603.invoke(interruptible_eval.clj:138)
at clojure.lang.AFn.run(AFn.java:22)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
REPL-y 0.3.2, nREPL 0.2.0-beta5NoSuchMethodError clojure.tools.nrepl.StdOutBuffer.length()I clojure.tools.nrepl.middleware.session/session-out/fn--7630 (session.clj:43)NoSuchMethodError clojure.tools.nrepl.StdOutBuffer.length()I clojure.tools.nrepl.middleware.session/session-out/fn--7630 (session.clj:43)#Exception in thread "nREPL-worker-1" java.lang.NoSuchMethodError: clojure.tools.nrepl.StdOutBuffer.length()I
at clojure.tools.nrepl.middleware.session$session_out$fn__7630.doInvoke(session.clj:43)
at clojure.lang.RestFn.invoke(RestFn.java:460)
at clojure.tools.nrepl.middleware.session.proxy$java.io.Writer$ff19274a.write(Unknown Source)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at clojure.core$fn__5471.invoke(core_print.clj:191)
at clojure.lang.MultiFn.invoke(MultiFn.java:231)
at clojure.core$pr_on.invoke(core.clj:3392)
at clojure.core$pr.invoke(core.clj:3404)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$prn.doInvoke(core.clj:3437)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$println.doInvoke(core.clj:3457)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.main$repl_caught.invoke(main.clj:158)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__7569$fn__7582.invoke(interruptible_eval.clj:76)
at clojure.main$repl$fn__6634.invoke(main.clj:259)
at clojure.main$repl.doInvoke(main.clj:257)
at clojure.lang.RestFn.invoke(RestFn.java:1096)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__7569.invoke(interruptible_eval.clj:56)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:41)
at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__7610$fn__7613.invoke(interruptible_eval.clj:171)
at clojure.core$comp$fn__4192.invoke(core.clj:2402)
at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__7603.invoke(interruptible_eval.clj:138)
at clojure.lang.AFn.run(AFn.java:22)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Error loading namespace; falling back to userNoSuchMethodError clojure.tools.nrepl.StdOutBuffer.length()I clojure.tools.nrepl.middleware.session/session-out/fn--7630 (session.clj:43)NoSuchMethodError clojure.tools.nrepl.StdOutBuffer.length()I clojure.tools.nrepl.middleware.session/session-out/fn--7630 (session.clj:43)user=>
I need some help interpreting what this means and how to fix it. Running JDK 1.8.0_20
This is a known bug with lein 2.4.3. Until a new stable version is available, it can be fixed by running the following code:
lein upgrade 2.4.2. Also, this problem only shows up in projectless repls, if you create a new project, and run lein from inside the project directory, the error will not occur.
I'm using Noir.
This is my project.clj
(defproject noir "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]])
lein run gives me this error:
No :main namespace specified in project.clj.
Where am I going wrong?
Now, if I add :main my-website.server to project.clj, I get this error:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: my-website.server
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:616)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:225)
at user$eval29.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: my-website.server
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
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
The problem is that lein don't know where to locate your -main function:
First, you shall create .clj file to run. You can specify it's namespace using ns macro. Then you shall define -main function in this namespace:
(ns my-website.server
(:require [noir.server :as server]
[noir.core :refer [defpage]]))
(defpage "/welcome" []
"Welcome to Noir!")
(defn -main
[& args]
(server/start 4000))
Then you shall configure your project.clj:
(defproject my-website "0.1.0-SNAPSHOT"
:description "..."
:dependencies [[org.clojure/clojure "1.4.0"]
[noir "1.2.2"]]
:main my-website.server)
[noir "1.2.2"] is the latest stable version of noir. It's best to use this one.
Do not forget to place this file into your source directory. Bu default its ./src dir in your project root. So, if your namespace is called my-website.server then lein will look for it in ./src/my-website/server.clj file (or in ./src/my_website/server.clj, I'm not sure).
Now lein run will cause lein to enter namespace my-website.server and then to run (-main) function.
See sample lein project for more info.
You can also generate project.clj for your noir project using lein noir template.
I'm just starting learning Clojure and web programming. I've installed Leiningen 2.0.0-preview2 on Clojure 1.3.0 and it can create projects correctly. But I always got That's not a task. Use "lein help" to list all tasks. error when I ran lein plugin install lein-noir 1.2.1 to install noir.
I've also tried to added lein-noir as a :dev-dependencies into project.clj and ran lein deps but it did nothing.
Does anyone know what's the problem and how can I resolve it. Thanks a lot!
My environment:
Mac OS X 10.6.8
Java 6
Leiningen 2.0.0-preview2
I've also tryed Leiningen 1.7 but got different error and someone said it's because leiningen 1.7 can only work with Clojure 1.2.x
Here's the error when I use Leiningen 1.7:
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.KeywordLookupSite.(ILclojure/lang/Keyword;)V
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Compiler.eval(Compiler.java:6476)
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$script_opt.invoke(main.clj:339)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:551)
at clojure.lang.Var.invoke(Var.java:426)
at clojure.lang.AFn.applyToHelper(AFn.java:193)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.NoSuchMethodError: clojure.lang.KeywordLookupSite.(ILclojure/lang/Keyword;)V
at leiningen.util.plugins$stale_QMARK_.(plugins.clj:68)
at leiningen.util.plugins__init.load(Unknown Source)
at leiningen.util.plugins__init.(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:482)
at leiningen.core$loading__4414__auto__.invoke(core.clj:1)
at leiningen.core__init.load(Unknown Source)
at leiningen.core__init.(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:398)
at clojure.core$load$fn__4610.invoke(core.clj:5386)
at clojure.core$load.doInvoke(core.clj:5385)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5200)
at clojure.core$load_lib.doInvoke(core.clj:5237)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:602)
at clojure.core$load_libs.doInvoke(core.clj:5271)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:604)
at clojure.core$use.doInvoke(core.clj:5363)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at user$eval1.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
... 11 more
If you have added lein-noir to .lein/profiles.clj like above you need to run the command :
lein new noir yoursitename.
Not lein noir new my-website !
Also add lein-noir "1.2.1"
Leiningen 2 is very new. Most of the documentation out there is still describing how to do things with leiningen 1.7.0. The ways you've tried to install lein-noir don't work with leiningen 2. The documentation describing how lein version 2 is different from lein 1.7.0 can be found here.
In a nutshell, you need to create a profiles.clj file in your ~/.lein directory. To specify you want to use lein-noir, your ~/.lein/profiles.clj file should look like:
{:user {:plugins [[lein-noir "1.2.1"]]}}
Now you can create a new noir project by typing:
lein new noir projectname
I have a simple web app with this project.clj:
(defproject squirrel-money "1.0.0-SNAPSHOT"
:description "Squirrel Money"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.5.3"]
[ring/ring-jetty-adapter "0.3.5"]
[hiccup "0.3.1"]
[postgresql "8.4-701.jdbc4"]
[clj-time "0.2.0-SNAPSHOT"]]
:dev-dependencies [[lein-eclipse "1.0.0"]]
:main squirrel-money.main
:repl-init-script "src/squirrel_money/init_repl.clj")
My main looks like this:
(ns squirrel-money.main
(:gen-class)
(:use
[compojure.core]
[ring.adapter.jetty])
(:require
[compojure.route :as route]
[squirrel-money.savings :as savings]))
(defn launch [routedef]
(run-jetty routedef {:port 17080}))
(defroutes money-routes
(GET "/savings" [] (savings/render))
(route/not-found "Page not found"))
(defn -main [& args] (launch money-routes))
With REPL works just fine. However, when I generate a jar with lein uberjar and try to execute it as:
java -jar squirrel-money-1.0.0-SNAPSHOT-standalone.jar
It dies with this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: compojure/response/Renderable
at squirrel_money.main$fn__1067.invoke(main.clj:18)
at squirrel_money.main__init.load(Unknown Source)
at squirrel_money.main__init.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:1578)
at clojure.lang.RT.load(RT.java:399)
at clojure.lang.RT.load(RT.java:381)
at clojure.core$load$fn__4511.invoke(core.clj:4905)
at clojure.core$load.doInvoke(core.clj:4904)
at clojure.lang.RestFn.invoke(RestFn.java:409)
at clojure.lang.Var.invoke(Var.java:365)
at squirrel_money.main.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: compojure.response.Renderable
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 13 more
What am I doing wrong? How to get it to work?
Not sure if that matters, but I noticed that inside the jar my files, clojure itself and Java libs are unpacked as .class files, while all clojure libs are present only as plain .clj files.
This seems to be a leinigen 1.4.0 bug. You might want to try creating an uberjar with leiningen 1.3.1.
Edit:
Leiningen 1.4.0 deletes non-project .class files to work around a Clojure bug (see CLJ-322). Apparently this behavior can sometimes cause problems.
You can keep leiningen 1.4.0 from deleting non-project .class files by setting :keep-non-project-classes to true in your project.clj.
See the related leinigen issue for more info.