当我在终端中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
时却不起作用。我甚至没有得到任何其他错误,所以我更加困惑。
请有人帮忙。感谢
答案 0 :(得分:2)
您的-main
功能正在运行,并且在致电component/start
后退出,因为它没有阻止。来自the component page:
注意:您仍然需要保持应用程序的主线程运行,以防止JVM关闭。一种方法是阻止主线程等待某些信号关闭;另一种方法是将主线程线程/加入到你的一个组件中。线程。