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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top