Skip to content

Embedding REPLy

trptcolin edited this page Apr 24, 2013 · 4 revisions

If you'd like to use REPLy from your app, great!

This page walks you through an example of setting it up. I'm sure you already have a project ready if you're on this page, but if not, lein new foo && cd foo will get you one created.

In project.clj, get yourself a REPLy dependency and a :main namespace:

(defproject foo "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [reply "0.2.0-SNAPSHOT"]]
  :main foo.core)

Then, in src/foo/core.clj, add this to your :main function. There's a little song and dance here with ns-resolve to avoid transitively AOT'ing the world, but such is life.

(ns foo.core
  (:gen-class))

(defn -main [& args]
  (require 'reply.main)
  ((ns-resolve 'reply.main 'launch)
   {:custom-eval '(do (println "Welcome to this awesome app"))
    :skip-default-init true
    :port 9999}))

The :custom-eval/:skip-default-init/:port bits aren't necessary (though having a map in that function slot is required): they're just examples of things you might want to do or learn more about.

From this point you can run lein uberjar and then you've got a runnable uberjar that kicks off REPLy. To launch it, do something like java -jar target/foo-0.1.0-SNAPSHOT-standalone.jar, and your main class will run, with REPLy as part of it.

lein trampoline run will work as well if you don't need to bother with an uberjar.

Caveat: REPLy has a bunch of dependencies, so there's a very real chance of dependency hell. Don't say I didn't warn you.

Something went wrong with that request. Please try again.