Embedding swank-clojure in java program

Deadly 提交于 2019-12-04 12:01:18

问题


Based on the Embedding section of http://github.com/technomancy/swank-clojure, I'm using the following to test it out. Is there a better way to do this that doesn't use Compiler? Is there a way to programmatically stop swank? It seems start-repl takes control of the thread. What would be a good way to spawn off another thread for it and be able to kill that thread programatically.

import clojure.lang.Compiler; 
import java.io.StringReader; 

public class Embed { 
    public static void main(String[] args) throws Exception { 
        final String startSwankScript = 
            "(ns my-app\n" + 
                "  (:use [swank.swank :as swank]))\n" + 
                "(swank/start-repl) "; 
        Compiler.load(new StringReader(startSwankScript)); 
    } 
} 

Any help much appreciated, hhh


回答1:


Would it be acceptable to you to implement the Embed class in Clojure? You could do that with gen-class (see Meikel Brandmeyer's tutorial for details) and AOT compilation.

The code could go something like

(ns your-app.Embed
  (:require [swank.swank :as swank])
  (:gen-class
   :methods [[startSwank [] void]]))

(defn -startSwank []
  (swank/start-repl))

(add anything else you require); then in the Java part of your application, you could import your Clojure-prepared class, instantiate it and call .startSwank() on the instance.

Not sure about programmatically stopping Swank... I'd be curious to know of a good way to do that myself. (And I'll be back with an update if I figure it out; otherwise, I'd love to read somebody else's answer detailing how to go about that.)



来源:https://stackoverflow.com/questions/2661025/embedding-swank-clojure-in-java-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!