10

In the following link http://clojure.org/reference/repl_and_main#_launching_a_socket_server

it has detailed info about how to start socket REPL form java, but since I am using lein, so how to start from lein. If start from boot is good to run, I could also try to use boot.

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
Daniel Wu
  • 5,853
  • 12
  • 42
  • 93
  • Leiningen automatically starts the repl on a socket. Look at the banner it prints at startup to see which one it picked. – dsm Jan 21 '16 at 14:44
  • @dsm the author is talking about the new socket REPL in Clojure 1.8, not Leiningen's REPL. – Daniel Compton Jan 21 '16 at 19:37

2 Answers2

17

To start a socket repl, you need to pass this option to the JVM

-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"

In Leiningen, add this to your project.clj.

:jvm-opts ["-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"] ; notice that the map is not quoted.

and in Boot, export the environment variable BOOT_JVM_OPTIONS

export BOOT_JVM_OPTIONS='-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"'

Once your REPL is running, you can run telnet from a different terminal to connect to the socket REPL. REPLception!

$ telnet 127.0.0.1 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (+ 1 1)
2
user=>
Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
  • it's clear for boot as "export" is a linux command and I know how to use it. but for lein, you use ":jvm-opts...", should we I put? put it into project.clj? – Daniel Wu Jan 21 '16 at 23:17
2

boot has an upcoming socket-server task. As of boot 2.7.1, a version that includes this task hasn't been released yet.

In the meantime you can use the following commands to launch Socket REPLs. To launch a Clojure process with a Socket REPL listening on port 50505 using boot, use:

boot -i "(do (require 'clojure.core.server) (clojure.core.server/start-server {:port 50505 :name :repl :accept 'clojure.core.server/repl}))" wait

Using Leiningen:

JVM_OPTS='-Dclojure.server.myrepl={:port,50505,:accept,clojure.core.server/repl}' lein repl

Using a pain Clojure jar:

java -Dclojure.server.myrepl="{:port 50505 :accept clojure.core.server/repl}" -jar ~/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar
loevborg
  • 1,774
  • 13
  • 18