lein ring server: "That's not a task" - clojure

I'm trying to build the hello-world example for compojure and it's failing to start the ring task.
$ lein version
Leiningen 1.7.1 on Java 1.7.0_65 OpenJDK 64-Bit Server VM
$ lein new compojure test
Created new project in: /home/myaccount/test
Look over project.clj and start coding in compojure/core.clj
$ cd test/
$ lein ring server
That's not a task. Use "lein help" to list all tasks.
I've also tried using the hello-world on the luminous site, which also says it can't find that task or other examples, where lein complains that I'm using the wrong number of arguments even if I pull the line straight from their tutorial.
$ lein new luminus guestbook +h2
Wrong number of arguments to new task.
Expected ([project-name] [project-name project-dir])

I quess you are missing the ring and compjure plugins in the project.clj file:
(defproject compojure "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:plugins [[lein-ring "0.8.8"]
[compojure "1.1.6"]]
;; once you have the above, you'll see that you need
;; to configure ring. This is the most simple example:
:ring {:handler compojure.core/handler})
Of course you have to define a handler function in src/compojure/core.clj! See here or here for a very nice introduction.

Related

Prevent 'lein repl' in SublimeREPL from echoing the previous command

I'm running Sublime Text 3 Build 3117 on both OS X 10.10.5 and Ubuntu 16.04. I just installed Leiningen 2.6.1 on both, and I'm starting to play around in SublimeREPL. I'm following the lein tutorial. Here is my project.clj, in case it matters:
(defproject my-stuff "0.1.0"
:description "Leiningen Tutorial Project"
:url "http://example.com/FIXME"
:license {:name "MIT"
:url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot my-stuff.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}}
:repl-options {
;; custom prompt
prompt (fn [ns] (str "> " ))
}
)
Now, when I run lein repl in the my-stuff directory from the command line and run an arbitrary command (I've been using (+ 1 2 3)), it prints out the answer nicely:
However, if I run lein repl from SublimeREPL with project.clj focused, and run the same command, it echoes the command before printing the return value:
I've also created a lein trampoline run -m clojure.main command for SublimeREPL, and it doesn't have the echoing problem:
Basically, what I would like to do is be able to run a REPL using project.clj, but not have every command echoed before the output is printed. I can't seem to figure out how to run a trampoline REPL in Sublime using project.clj, if that's the best option. If there's a different way, i.e., using lein repl, I just want to get rid of the command echo, and make it look similar to what appears when I run it from the command line.
Thanks to some help at the Sublime Text Forum, I got an answer: you simply need to put "suppress_echo": true in the Main.sublime-menu file where the Clojure menu options are defined. In this case, open Packages/SublimeREPL/config/Clojure/Main.sublime-menu, put a comma , after "extend_env": {"INSIDE_EMACS": "1"}, then on the next line put "suppress_echo": true and you're all set.

Clojure ring server seems to be missing dependencies on slf4j

I've been trying to follow a number of tutorials on building a web app in Clojure, but I keep running into the same problem. To take the simplest case, I tried following this tutorial: http://drtom.ch/posts/2012-12-10/An_Introduction_to_Webprogramming_in_Clojure_-_Ring_and_Middleware/
When I get to the step that starts the server (run-jetty handler {:port 8383}), I get the following error:
NoSuchMethodError org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple; org.eclipse.jetty.util.log.JettyAwareLogger.log (JettyAwareLogger.java:613)
I asked lien to show me the classpath, and sure enough, org.slf4j.helpers.MessageFormatter isn't in there anywhere.
I've run into this on pretty much every ring-based web tutorial I've tried, so either I've got something configured weird (I updated and reinstalled lein, blew away my ~/.m2 and rebuilt, etc), or something has changed in the myriad dependencies that get put together to make the classpath.
Any ideas what's going on here?
EDIT
I've got further information -- I created a VM in virtualbox, installed OpenJDK and lein, and created a project there. It worked fine. Since I had created it in a directory shared with the host, I then tried doing "lein ring server" in the same directory from the host, and it failed with the above error.
So I did "lein classpath" both in the vm and in the host and compared the results -- they're identical. I also checked that they're running the same build of the same JVM (OpenJDK 64-bit build 24.51-b03).
So, if they're running the same JVM with identical classpaths, what's left?
Can you try updating the dependencies like the following?
(defproject ..........
:dependencies [[org.clojure/clojure "1.5.1"]
[ring/ring-core "1.1.8"]
[ring/ring-jetty-adapter "1.1.8"]
[compojure "1.1.3"]]
:main quickstart.core
:min-lein-version "2.0.0"
:plugins [[lein-ring "0.8.10"]]
:ring {:handler quickstart.core/handler})
If you use the lein ring plugin as configured above, you can start the application like:
lein ring server

Leiningen fails to start a REPL on WinXP machine

I'm using a WinXP (sp3) machine with clojure-1.5.1, leiningen-2.3.4, and the Java 1.7.0_45 jdk. I have no trouble creating a new project with leiningen, starting a clojure shell, or creating and running java programs. However, the following command (please see below) results in the error message(s) displayed. I have added the clojure-1.5.1 and leiningen-2.3.4-standalone.jars to user and system path variables in addition to the creation of a new user and system environmental variable, LEIN_JAR that points to the location of the leiningen.jar file. The classpath for both the user and system variables has also been edited as above. My lein.bat is not missing any double quotes around the location of the LEIN_JAR setting as another poster stated in assisting another beginning(?) user of Clojure. Any constructive help would be appreciated.
My project.clj file :
(defproject test10 "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]])
Edit 2: lein version command output
C:\>lein version
Leiningen 2.3.4 on Java 1.7.0_45 Java HotSpot(TM) Client VM
C:\>lein repl
Error: Could not find or load main class -Dfile.encoding=UTF-8
Exception in thread "Thread-4" clojure.lang.ExceptionInfo: Subprocess failed {:e
xit-code 1}
at clojure.core$ex_info.invoke(core.clj:4327)
at leiningen.core.eval$fn__3532.invoke(eval.clj:226)
at clojure.lang.MultiFn.invoke(MultiFn.java:231)
at leiningen.core.eval$eval_in_project.invoke(eval.clj:326)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:619)
at leiningen.repl$server$fn__7443.invoke(repl.clj:201)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:617)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1788)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:621)
at clojure.core$bound_fn_STAR_$fn__4102.doInvoke(core.clj:1810)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:744)
REPL server launch timed out.
C:\>
Thank you for the response. The output from lein version looks good. Sorry for the long message :)
Here is my approach to trouble shooting this further. Please make sure you are checking the system logs maintained by Windows. Pertinent messages could be routed to the system logs and not displayed in the console.
So far it appears leinegen can execute, some, but not all of it's commands. If you execute "lein help", you will get list of available commands.
My first thought is, leinegen is having trouble with the "lein repl" defaults. Thus, instead having leinegen choose default values for host and port, set them explictily in the command line. For example: "lein repl :start :host localhost :port 5554" or "lein repl :start :host 127.0.0.1 :port 5554".
I would change in to your "example" directory and verify that "lein deps", "lein check" and "lein compile" all run error free.
Finally, I would edit the example project. Add the following line to project.clj (right after the :dependencies clause)
:main example.core
That line tells leinegen what the entry point of the "example" program is.
Next we need to edit the "src/example/core.clj" file. Delete the contents and replace it with the following "hello word":
(ns example.core)
(defn -main [& args ]
(println "Hello, World!"))
Now, from the root of the example project (C:/>example) run "lein run". Please post the results. If "lein run" succeeds try "lein repl" one more time from the root of the example project.
Again. make sure you check the Window's logs for messages. It might also help to run "lein deps", "lein check" and "lein complile" from the root of the example project. See if any errors are raised that are more helpful.
Sorry I don't use MS Windows. However I have a couple suggestions.
You said you were able to create a new project with leiningen. What disk/directory did you create that project in?
Per your post, it looks like you are issuing the "lein repl" command from the root disk directory of your "c:" drive. Is that where you created a project?
If you change to a different disk/directory, do you get the same error message?
Perhaps leiningen is picking some artifacts it can't resolve in your root directory (I.E. C:/>). Thus, check to see if you can run "lein repl" from a different disk directory.
If you are only getting an error when you running "lein repl" from the root of a project directory, please post some information about the project (E.G. the contents of your project.clj file).
Hope that helps.
Check to make sure that lein is not in a directory whose path has any spaces or capitalized characters in it.
Make sure the JDK is in a directory with no spaces or capitalized characters in it.
Make sure JAVA_HOME is set
Make sure java is in your SYSTEM path

How to define project.clj for both lein run and lein repl to work?

I'm new to Clojure, and I don't quite understand how to write my project.clj so it works for both lein repl and lein run. Here it is (whole path: ~/my-project/project.clj):
(defproject my-project "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:main my-project.core/hello
)
Then I have my ~/my-project/src/my_project/core.clj file
(ns my-project.core)
(defn hello []
(println "Hello world!")
)
lein run works just fine but I get a FileNotFoundException when running lein repl:
~/my-project$ lein run
Hello world!
~/my-project$ lein repl
REPL started; server listening on localhost port 42144
FileNotFoundException Could not locate hello__init.class or hello.clj on classpath: clojure.lang.RT.load (RT.java:430)
clojure.core=>
How should I edit the project.clj to solve this? Or do I have to call lein repl in a different way?
Thanks in advance.
EDIT: tried with lein deps and lein compile, but still the same error
~/my-project$ lein version
Leiningen 1.7.1 on Java 1.6.0_27 OpenJDK Client VM
~/my-project$ lein deps
Copying 1 file to /home/yasin/Programming/Clojure/my-project/lib
~/my-project$ lein compile
No namespaces to :aot compile listed in project.clj.
~/my-project$ lein repl
REPL started; server listening on localhost port 41945
FileNotFoundException Could not locate hello__init.class or hello.clj on classpath: clojure.lang.RT.load (RT.java:430)
One thing you could do to get it to work would be to change core.clj to:
(ns my-project.core
(:gen-class))
(defn hello []
(println "Hello world!"))
(defn -main []
(hello))
And edit the project.clj to:
(defproject my-project "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:main my-project.core)
The (:gen-class) will tell the compiler to generate a Java class for the namespace, and the :main directive in project.clj will tell lein run to run the main method on the class, which is given by -main. Why lein repl was failing to find my-project.core/hello is unclear to me, but I don't know much about leiningen internals.

leiningen run a AOT compiled java class

Context
If I want Lein 1.7 to start out with a particular class loaded, I do:
:repl-init init.init
Now, instead of having lein load up a *.clj file, I want lein to do the equiv of "java Foo", where Foo is classes/Foo.class
Question:
My project.clj look alike:
(defproject ...
:aot [Foo]
???? )
What do I put in ???? to make "lein repl" startup by executing "java Foo" ?
Thanks!
If I understand your question, you can still use :repl-init for this by having a call to the class you want pre-loaded in a namespace that gets loaded by the repl. in this example i'm using println statement as a standin for the setup you want done :-)
project.clj:
(defproject foooo "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:aot [foooo.core]
:main foooo.core
:repl-init foooo.core)
core.clj
(ns foooo.core
(:gen-class))
(println "setting up for fun")
(defn -main [])
compiling:
arthur#a:~/foooo$ lein compile
Compiling foooo.core
Compilation succeeded.
running:
arthur#a:~/foooo$ CLASSPATH=./lib/clojure-1.3.0.jar:./classes/ java foooo.core 1
setting up for fun
or:
arthur#a:~/foooo$ lein run
setting up for fun
REPLing:
arthur#a:~/foooo$ lein repl
REPL started; server listening on localhost port 63392
setting up for fun
foooo.core=>