Java调用clojure
clojure
(ns r2.test2
(:gen-class
:methods [#^{:static true} [getMessage [String] String]])
)
(defn -getMessage [name]
(println (str ("hello " name "!"))))
JAVA端
import com.ociweb.clj.Demo; // class created by compiling Clojure source file
public class Main {
public static void main(String[] args) {
String message = Demo.getMessage("Mark");
System.out.println(message);
}
}
好像只在命令行中使用可以....在工具里调用不到....纠结..
下面是网站上提供的步骤....可惜哥英语不好= =看的蛋疼....
Here are the steps to build and run it.
cd to the directory containing the src and classes directories.
Start a REPL by entering "clj".
Enter "(compile 'com.ociweb.clj.Demo)".
Exit the REPL (ctrl-d or ctrl-c).
Enter "javap -classpath classes com.ociweb.clj.Demo" to see the methods in the generated class.
Enter "javac -cp classes Main.java".
Enter "java -cp .:classes:path/clojure.jar Main.java". Use semicolons instead of colons under Windows.
The output should be "Hello, Mark!".
作者“Loli控的博客”
补充:软件开发 , Java ,