在java程序中嵌入swank-clojure [英] Embedding swank-clojure in java program

查看:212
本文介绍了在java程序中嵌入swank-clojure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://github.com/technomancy/swank-clojure
我使用以下来测试它。有没有更好的方法来做
这不使用编译器?有没有办法以编程方式
停止swank?似乎start-repl控制线程。什么
将是一个好的方法来产生另一个线程为它,并能够
杀死该线程编程。

  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\\\
+
(:use [swank.swank:as swank]))\\\
+
(swank / start-repl)
Compiler.load(new StringReader(startSwankScript));
}
}

任何帮助非常感激,
hhh

是否可以在Clojure中实现 Embed ?你可以使用 gen-class (请参阅 Meikel Brandmeyer的教程)和AOT编译。



代码可以像

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

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

(添加您需要的任何其他内容);然后在应用程序的Java部分中,您可以导入您的Clojure准备的类,实例化它,并在实例上调用 .startSwank()



不知道程序化停止Swank ...我很想知道一个很好的方法来做自己。 (如果我想出来,我会回来一个更新;否则,我想阅读别人的答案,详细说明如何去做。)


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

解决方案

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.)

这篇关于在java程序中嵌入swank-clojure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆