Lein没有运行我的主要方法

时间:2017-05-09 15:08:20

标签: clojure leiningen

Lein没有运行我的主要方法。我甚至引入了语法错误,但它并没有抓住它们。我真的很难过。我非常感谢社区的任何帮助。

我相信主要方法是正确指定的。第一个代码示例是server.clj,使用main方法。接下来是我的project.clj。

  (ns naac.server
  (:require [naac.handler :refer [handler]]
            [config.core :refer [env]]
            [migratus.core :as migratus]
            [ring.adapter.jetty :refer [run-jetty]]
            [naac.db :refer [load-db!]])
  (:gen-class))

(def db-config {:store :database
                :db (get (System/getenv) "DATABASE_URL"
                    "jdbc:postgresql://localhost:5432/jeff")
                :migration-dir "migrations"})

 (defn -main [& args]
   (println args)
   (doseq [a args]
     (cond
       (= a "migrate")
         (do
           (println "Migrate database...")
           (migratus/migrate  db-config)
           (println "...Migration done."))
       (= a "rollback")
         (do
           (println "Rollback database...")
           (migratus/rollback db-config)
           (println "...Rollback done."))
       (= a "load")
         (do
           (println "Load database...")
           (load-db!)
           (println "...Load done."))))

  (if (> (count args) 0) (System/exit 0))

  (let [port (Integer/parseInt (or (env :port) "3000"))]
   (run-jetty handler {:port port :join? false})))

我的project.clj:

 (defproject naac "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.229"]
                 [reagent "0.6.0"]
                 [re-frame "0.9.2"]
                 [compojure "1.5.0"]
                 [yogthos/config "0.8"]
                 [migratus "0.9.2"]
                 [ring "1.4.0"]
                 [com.layerware/hugsql "0.4.7"]
                 [org.postgresql/postgresql "9.4.1207"]]

  :plugins [[lein-cljsbuild "1.1.4"]
            [migratus-lein "0.4.1"]]

  :min-lein-version "2.5.3"

  :source-paths ["src"]

  :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]

  :figwheel {:css-dirs ["resources/public/css"]
             :ring-handler naac.handler/dev-handler}

  :profiles
  {:dev {:dependencies [[binaryage/devtools "0.8.2"]]
         :plugins      [[lein-figwheel "0.5.9"]]
         :resource-paths ["resources/config"]}
   }

  :migratus {:store :database
             :db ~(get (System/getenv) "DATABASE_URL"
                    "jdbc:postgresql://localhost:5432/jeff")
             :migration-dir "migrations"}

  :cljsbuild
  {:builds
   [{:id           "dev"
     :source-paths ["src/cljs"]
     :figwheel     {:on-jsload "naac.core/mount-root"}
     :compiler     {:main                 naac.core
                    :output-to            "resources/public/js/compiled/app.js"
                    :output-dir           "resources/public/js/compiled/out"
                    :asset-path           "js/compiled/out"
                    :source-map-timestamp true
                    :preloads             [devtools.preload]
                    :external-config      {:devtools/config {:features-to-install :all}}
                    }}

    {:id           "min"
     :source-paths ["src/cljs"]
     :jar true
     :compiler     {:main            naac.core
                    :output-to       "resources/public/js/compiled/app.js"
                    :optimizations   :advanced
                    :closure-defines {goog.DEBUG false}
                    :pretty-print    false}}


    ]}

  :main naac.server

  :aot [naac.server]

  :uberjar-name "naac.jar"

  :prep-tasks [["cljsbuild" "once" "min"] "compile"]
  )

我的目录结构可以在this image中看到。如果您需要更深的嵌套级别,可以看到它here

当我运行lein时,我得到了这个输出:

    Compiling ClojureScript...
2017-05-09 12:12:12.739:INFO::main: Logging initialized @2438ms
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Starting migrations
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
WARNING: skipping: '.DS_Store' migrations must match pattern: ^(\d+)-([^\.]+)((?:\.[^\.]+)+)$
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Ending migrations
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Starting migrations
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
WARNING: skipping: '.DS_Store' migrations must match pattern: ^(\d+)-([^\.]+)((?:\.[^\.]+)+)$
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Ending migrations
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Starting migrations
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
WARNING: skipping: '.DS_Store' migrations must match pattern: ^(\d+)-([^\.]+)((?:\.[^\.]+)+)$
May 09, 2017 12:12:12 PM clojure.tools.logging$eval18$fn__22 invoke
INFO: Ending migrations

1 个答案:

答案 0 :(得分:1)

:source-paths中的问题是project.clj。 Lein希望您的命名空间文件夹直接位于源路径中。

您可以将naac文件夹直接移至src(例如src/naac/server.clj)或使用["src/clj"]作为:source-paths

的值