Clojure - lein没有启动我的应用程序

时间:2017-03-09 16:17:22

标签: clojure

当我在终端中lein run时,我的应用程序无法启动。我得到的只是

me@XPS:~/Clojure/myapp/web$ lein run
INFO  org.eclipse.jetty.util.log: Logging initialized @10745ms
me@XPS:~/Clojure/myapp/web$

该应用尚未启动,我不知道为什么

这是我的core.clj

(ns myapp.core
  (:require [yada.yada :as yada :refer [resource as-resource]]
            [yada.resources.file-resource :refer [new-directory-resource]]
            [aero.core :refer [read-config]]
            [web.view :as view]
            [web.routes :as routes]
            [clojure.java.io :as io]
            [aero.core :refer [read-config]]
            [com.stuartsierra.component :as component]
            [clojure.java.jdbc :as jdbc]
            [clojure.tools.namespace.repl :refer (refresh)]
            [ring.adapter.jetty :as jetty]
            [environ.core :refer [env]]))

(defrecord Listener [listener]
  component/Lifecycle
  (start [component]
    (assoc component :listener (yada/listener
                                 ["/"
                                  [(view/view-route)
                                   routes/route-handler
                                   ["public/" (new-directory-resource (io/file "target/cljsbuild/public") {})]
                                   [true (as-resource nil)]]]           )))
  (stop [component]
    (when-let [close (-> component :listener :close)]
      (close))
    (assoc component :listener nil)))

(defn new-system []
  (component/system-map
    :listener (map->Listener {})
    ))

(def system nil)

(defn init []
  (alter-var-root #'system
                  (constantly (new-system))))

(defn start []
  (alter-var-root #'system component/start))

(defn stop []
  (alter-var-root #'system
                  (fn [s] (when s (component/stop s)))))

(defn go []
  (init)
  (start))

(defn reset []
  (stop)
  (refresh :after 'web.core/go))

(defn -main
  [& [port]]
  (component/start (new-system)))

如果我lein repl(go),我可以完美地启动应用,但在执行lein run时却不起作用。我甚至没有得到任何其他错误,所以我更加困惑。

请有人帮忙。感谢

1 个答案:

答案 0 :(得分:2)

您的-main功能正在运行,并且在致电component/start后退出,因为它没有阻止。来自the component page

  

注意:您仍然需要保持应用程序的主线程运行,以防止JVM关闭。一种方法是阻止主线程等待某些信号关闭;另一种方法是将主线程线程/加入到你的一个组件中。线程。