[SOLVED] Can't run REPL with Leinengen

Hi all! I have a problem. Leiningen runs my application instead of REPL.

project.clj:

(defproject patients "0.1.0-SNAPSHOT"
  :description "Test app"
  :url ""
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}

  :dependencies [[org.clojure/clojure "1.9.0"]

                 [ring/ring-core "1.9.5"]
                 [ring/ring-jetty-adapter "1.9.5"]

                 [compojure "1.7.0"]]

  :main patients.app

  :profiles {:dev {:plugins []
                   :dependencies []
                   :source-paths ["dev"]}})

src/patients/app.clj:

(ns patients.app)

(require '[ring.adapter.jetty :refer [run-jetty]])
(require '[compojure.core :refer [GET ANY defroutes]])

(defn page-index [request]
  {:status 200
   :headers {"content-type" "text/plain"}
   :body "Application index!"})

(defn page-404 []
  {:status 404
   :headers {"content-type" "text/plain"}
   :body "Page not found."})

(defroutes app
  (GET "/"     request (page-index request))
  (ANY "/ping" _ {:status 200 :headers {"content-type" "text/plain"} :body "pong"})
  page-404)

(run-jetty app {:port 8080 :join? true})

Terminal output:

lania-kea@lania-kea-macbook-pro patients % (main) 
â–¸ lein --version
Leiningen 2.9.9 on Java 11.0.13 OpenJDK 64-Bit Server VM
lania-kea@lania-kea-macbook-pro patients % (main) 
â–¸ lein repl
2022-08-10 19:13:23.958:INFO::main: Logging initialized @5437ms to org.eclipse.jetty.util.log.StdErrLog
2022-08-10 19:13:25.549:INFO:oejs.Server:main: jetty-9.4.44.v20210927; built: 2021-09-27T23:02:44.612Z; git: 8da83308eeca865e495e53ef315a249d63ba9332; jvm 11.0.13+8
2022-08-10 19:13:25.598:INFO:oejs.AbstractConnector:main: Started ServerConnector@71f437d7{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-08-10 19:13:25.602:INFO:oejs.Server:main: Started @7081ms
REPL server launch timed out.

Server works well, all routes and 404 page are correctly available in browser. But I need REPL.
Please help, because I can’t go on my education process =(

I’m not entirely sure about this, but I think your “(run-jetty…)” process is locking up the REPL connection. When I run programs like this I usually start the REPL independently, from the command line, run my “run whatever” or (-main), and “jack in” from my editor to work with the REPL.

2 Likes

Yeah, this is pretty much what is happening.

You should move the run-jetty call to a function, and invoke that function manually once the REPL gets going.

2 Likes

Thank you all for answers!
Helped to move server invocation to -main function.

1 Like

Use :join false when starting jetty app server to return to the REPL terminal prompt after the server starts

(run-jetty app {:port 8080 :join? false}

Otherwise with true the jetty sever keeps hold of the execution thread and blocks the REPL prompt from showing

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.