├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── com └── github └── austinc └── jnrepl └── Jnrepl.java /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | pom.xml.asc 3 | *.jar 4 | *.class 5 | /lib/ 6 | /classes/ 7 | /target/ 8 | /checkouts/ 9 | .lein-deps-sum 10 | .lein-repl-history 11 | .lein-plugins/ 12 | .lein-failures 13 | .nrepl-port 14 | .idea/ 15 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jnREPL 2 | This library facilitates embedding a Clojure nREPL within a Java application. 3 | The API has two static methods: 4 | 5 | Jnrepl.startRepl(9091L); // start an nREPL server 6 | Jnrepl.shutdownRepl(); // shut it down 7 | 8 | 9 | The repl port defaults to `9090`. This default can overriden with the JVM arg `-Djnrepl.port=9091` 10 | 11 | 12 | ### Example connecting with leiningen 13 | 14 | `$ lein repl :connect localhost:9090` 15 | 16 | ### Maven coordinates 17 | 18 | 19 | com.github.austinc 20 | jnrepl 21 | 1.2 22 | 23 | 24 | Compatible with JVM 1.6+ 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.austinc 8 | jnrepl 9 | 1.2 10 | 11 | jnREPL 12 | Embed a Clojure nREPL in Java 13 | https://github.com/AustinC/jnREPL 14 | 15 | 16 | 17 | Unlicense 18 | http://unlicense.org/ 19 | 20 | 21 | 22 | 23 | 24 | Austin Chamberlin 25 | austin.r.chamberlin@gmail.com 26 | 27 | 28 | 29 | 30 | https://github.com/AustinC/jnREPL.git 31 | 32 | 33 | 34 | UTF-8 35 | 36 | 37 | 38 | 39 | org.clojure 40 | clojure 41 | 1.9.0 42 | 43 | 44 | org.clojure 45 | tools.nrepl 46 | 0.2.12 47 | 48 | 49 | org.clojure 50 | clojure 51 | 52 | 53 | 54 | 55 | org.slf4j 56 | slf4j-api 57 | 1.7.25 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-javadoc-plugin 67 | 2.10.1 68 | 69 | 70 | attach-javadocs 71 | 72 | jar 73 | 74 | 75 | 76 | 77 | 78 | maven-source-plugin 79 | 2.4 80 | 81 | 82 | attach-sources 83 | 84 | jar 85 | 86 | 87 | 88 | 89 | 90 | org.apache.maven.plugins 91 | maven-gpg-plugin 92 | 1.6 93 | 94 | 95 | sign-artifacts 96 | verify 97 | 98 | sign 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | sonatype 109 | https://oss.sonatype.org/service/local/staging/deploy/maven2 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/main/java/com/github/austinc/jnrepl/Jnrepl.java: -------------------------------------------------------------------------------- 1 | package com.github.austinc.jnrepl; 2 | 3 | import clojure.java.api.Clojure; 4 | import clojure.lang.IFn; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public class Jnrepl { 9 | 10 | final static Logger logger = LoggerFactory.getLogger(Jnrepl.class); 11 | 12 | private static Object serverInstance = null; 13 | 14 | /** 15 | * Start a clojure nREPL server 16 | */ 17 | public static synchronized void startRepl() { 18 | Long port = Long.parseLong(System.getProperty("jnrepl.port", "9090")); 19 | startRepl(port); 20 | } 21 | 22 | /** 23 | * Start a clojure nREPL server on the given port; 24 | */ 25 | public static synchronized void startRepl(long port) { 26 | 27 | if (null != serverInstance) { 28 | logger.warn("nrepl server already running, refusing to start another."); 29 | return; 30 | } 31 | 32 | try { 33 | IFn require = Clojure.var("clojure.core", "require"); 34 | require.invoke(Clojure.read("clojure.tools.nrepl.server")); 35 | IFn server = Clojure.var("clojure.tools.nrepl.server", "start-server"); 36 | serverInstance = server.invoke(Clojure.read(":port"), port); 37 | 38 | logger.info("Started clojure nREPL on port {}", port); 39 | } 40 | catch (Throwable e) { 41 | logger.error("Error starting nrepl", e); 42 | } 43 | } 44 | 45 | /** 46 | * Shutdown the nREPL server 47 | */ 48 | public static synchronized void shutdownRepl() { 49 | logger.info("Shutting down nrepl"); 50 | if (null == serverInstance) { 51 | return; 52 | } 53 | 54 | IFn shutdownFn = Clojure.var("clojure.tools.nrepl.server", "stop-server"); 55 | shutdownFn.invoke(serverInstance); 56 | serverInstance = null; 57 | } 58 | } 59 | --------------------------------------------------------------------------------