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控的博客”