Compojure应用程序在本地运行,但部署到Heroku时找不到主类lein
我有一个小Clojure网络应用程序,它是用ring和compojure构建的。虽然webapp在我的笔记本电脑上运行find local,但当我按下Heroku时,该应用程序崩溃。日志中的特定错误为Compojure应用程序在本地运行,但部署到Heroku时找不到主类lein,heroku,clojure,leiningen,ring,Heroku,Clojure,Leiningen,Ring,我有一个小Clojure网络应用程序,它是用ring和compojure构建的。虽然webapp在我的笔记本电脑上运行find local,但当我按下Heroku时,该应用程序崩溃。日志中的特定错误为 Starting process with command `java $JVM_OPTS lein ring server-headless 3000` app[web.1]: Error: Could not find or load main class lein app[web.1]
Starting process with command `java $JVM_OPTS lein ring server-headless 3000`
app[web.1]: Error: Could not find or load main class lein
app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Djava.rmi.server.useCodebaseOnly=true
heroku[web.1]: State changed from starting to crashed
我的project.clj
看起来像
(defproject hn-clj "0.1.1"
:description "foo"
:url "http://foo"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[compojure "1.3.1"]
[ring/ring-defaults "0.1.2"]
[clj-http-lite "0.2.0"]
[cheshire "5.4.0"]
[hiccup "1.0.5"]]
:plugins [[lein-ring "0.8.13"]]
:ring {:handler hn-clj.core.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}}
)
应用程序的入口点位于src/core/handler.clj
(ns hn-clj.core.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[compojure.handler :as handler]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[hn-clj.core.controllers.story :as story]
[hn-clj.core.controllers.users :as users]
))
(defroutes app-routes
(GET "/" [limit] (story/index limit))
(GET "/stories/:id" [id] (story/show-story id))
(GET "/users/:username" [username] (users/show username)))
(def app
(wrap-defaults app-routes site-defaults))
本地应用程序运行find withlein ring server headless 3000
,并在我的Procfile
中
web:java$JVM\u选择lein ring服务器headless 3000
虽然我没有创建
main-
函数,但这并不禁止应用程序在本地运行,我不明白为什么部署到Heroku时应用程序不会运行。我应该如何重构handler.clj
或Procfile
您的procfile应该是这样的:
web: lein ring server-headless $PORT
要检查应用程序是否可以在heroku上正常运行,可以使用foreman端口,该端口使用procfile
现在我正在使用Procfile for Heroku的文档。lein是一个构建工具,它和它的插件不包括在部署中,除非它们被明确列为依赖项(插件只用于开发/构建时,不用于部署)。我真的没有Heroku,但我通过快速搜索看到的一切都告诉我,heroku希望你的应用程序有一个正常工作的
-main
。运行你的应用程序的lein插件在开发中是很好的,但是你不应该在部署的服务器上依赖它们。