简体   繁体   中英

How can I start a socket REPL in Clojure 1.8 from leiningen or boot?

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.

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=>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM