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.

  1. cd to the directory containing the src and classes directories.
  2. Start a REPL by entering "clj".
  3. Enter "(compile 'com.ociweb.clj.Demo)".
  4. Exit the REPL (ctrl-d or ctrl-c).
  5. Enter "javap -classpath classes com.ociweb.clj.Demo" to see the methods in the generated class.
  6. Enter "javac -cp classes Main.java".
  7. Enter "java -cp .:classes:path/clojure.jar Main.java". Use semicolons instead of colons under Windows.
  8. The output should be "Hello, Mark!".

你可能感兴趣的:(java,clojure)