running clojure with leiningen
Asked Answered
J

3

20

I made a project named my-stuff and added to the project.clj so it looks like this

(defproject my-stuff "0.1.0-SNAPSHOT"
  :description "Testing lein"
  :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"] [clj-http "0.5.5"]]
  :main my-stuff.core)

so i can run the core however when I try to run lein run i get this

Learning\my-stuff>lein run
Exception in thread "main" java.lang.Exception: Cannot find anything to run for:
 my-stuff.core
    at user$eval5.invoke(form-init5159589073116828284.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6619)
    at clojure.lang.Compiler.eval(Compiler.java:6609)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.Compiler.loadFile(Compiler.java:7020)
    at clojure.main$load_script.invoke(main.clj:294)
    at clojure.main$init_opt.invoke(main.clj:299)
    at clojure.main$initialize.invoke(main.clj:327)
    at clojure.main$null_opt.invoke(main.clj:362)
    at clojure.main$main.doInvoke(main.clj:440)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)
    \Clojure\Learning\my-stuff>

even tho the core does exist in the source.

what do i do?

Jessamine answered 17/9, 2013 at 19:18 Comment(0)
M
29

Setting the :main key in the project.clj file directs Leiningen to run the -main function in the specified namespace. It is not included in the default lein template, so you need to add it.

(ns my-stuff.core)

(defn -main [& args]
  (println "Working!"))
Monochasium answered 17/9, 2013 at 19:23 Comment(2)
o yes! ok i see now all that time looking at it and i didnt realize the default function was called foo :( sorry it was so trivialJessamine
You can use lein new app my-proj to get the app template that will set all that for you too.Khmer
B
2

In my case "src/my-stuff/core.clj" file didn't have a "-main" method instead it was

(ns my-stuff.core)

(defn foo [& args]
  (println "Working!"))

I had to change "foo" to "-main".

Bharat answered 20/2, 2016 at 9:13 Comment(0)
A
0

Just another note - In my case I had a few entry points with -main in my haste I had copied the (ns ... from another file and forgot to change it.

project/core.clj
(ns project.core ...)

project/app.clj
(ns project.core ...) <-- oops

So double just check that the :main you specified actually exists in your project.

Alee answered 12/5, 2016 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.