从Java调用Clojure 1.3

从Java调用Clojure 1.3,clojure,clojure-java-interop,Clojure,Clojure Java Interop,我想从Java代码中调用Clojure函数。最近没有人问过这个问题,现有的答案对我也不适用。(Clojure 1.3,leiningen 1.7.0)。我有以下最低限度的计划: (ns thing.main (:gen-class :methods [#^{:static true} [foo [int] void]])) (defn -foo [i] (println "hello world, input is " i)) project.clj如下所示: (defproje

我想从Java代码中调用Clojure函数。最近没有人问过这个问题,现有的答案对我也不适用。(Clojure 1.3,leiningen 1.7.0)。我有以下最低限度的计划:

(ns thing.main
  (:gen-class
    :methods [#^{:static true} [foo [int] void]]))

(defn -foo [i] (println "hello world, input is " i))
project.clj如下所示:

(defproject thing "1.0.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.3.0"]]
  :aot [thing.main]
  :omit-source true)
java -cp '.:thing-1.0.0-SNAPSHOT-standalone.jar' HelloWorldApp
我生成一个uberjar,然后用这个小Java程序将它复制到同一个目录中

import thing.*;
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        main.foo(5);  // or, alternately, foo(5);
    }
}
我使用以下命令编译:

javac -cp '.:thing-1.0.0-SNAPSHOT-standalone.jar' HelloWorldApp.java

编译成功,但程序运行时失败(ClassNotFoundException)。直接调用foo的第二种形式,如foo(5),甚至不编译。我还尝试过在:gen class中使用或不使用“static”声明。

当我运行指定了类路径的程序时,它似乎对我有效。试着这样做:

(defproject thing "1.0.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.3.0"]]
  :aot [thing.main]
  :omit-source true)
java -cp '.:thing-1.0.0-SNAPSHOT-standalone.jar' HelloWorldApp
你说得对——我没有使用full-cp选项调用java。