【问题标题】:Compojure app runs locally, but cannot find main class lein when deployed to HerokuCompojure 应用程序在本地运行,但在部署到 Heroku 时找不到主类 lein
【发布时间】:2015-01-03 19:10:02
【问题描述】:

我有一个使用 ring 和 compojure 构建的小型 Clojure webapp。虽然 web 应用程序在我的笔记本电脑上本地运行,但当我推送到 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]: 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))

应用程序在本地运行查找 lein ring server-headless 3000 和我的 Procfile 我已经放了

web: java $JVM_OPTS lein ring server-headless 3000

虽然我没有创建main-函数,但这并不禁止应用程序在本地运行,我不明白为什么应用程序在部署到Heroku时无法运行。我应该如何重构handler.cljProcfile

【问题讨论】:

  • lein 是一个构建工具,它及其插件不包含在部署中,除非它们被明确列为依赖项(插件仅用于开发/构建时,而不用于部署)
  • 我并不是真的没有 heroku,但我通过快速搜索看到的所有内容都告诉我 heroku 希望你的应用程序有一个工作的-main。用于运行您的应用程序的 lein 插件在开发中非常有用,但您不应该在部署的服务器中依赖它们。

标签: heroku clojure leiningen ring


【解决方案1】:

你的 procfile 应该是这样的:

 web: lein ring server-headless $PORT

要检查您的应用程序是否可以在 heroku 上正常运行,您可以使用 foreman 端口,该端口使用 procfile。

这些天我在使用gaffer,而Procfile for Heroku 的文档是here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 2021-04-10
    • 2020-10-22
    • 1970-01-01
    • 2020-07-17
    • 2021-03-24
    • 2021-04-17
    相关资源
    最近更新 更多