Calling Clojure 1.3 from Java
I would like to call a Clojure function from Java code. This question hasn't been asked lately and the existing answers don't work for me. (Clojure 1.3, leiningen 1.7.0). I have the following minimal program:
(ns thing.main
(:gen-class
:methods [#^{:static true} [foo [int] void]]))
(defn -foo [i] (println "hello world, input is " i))
Clj project looks like this:
(defproject thing "1.0.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.3.0"]]
:aot [thing.main]
:omit-source true)
I am generating uberjar and I am copying it to the same directory with this little Java program.
import thing.*;
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!");
main.foo(5); // or, alternately, foo(5);
}
}
I will compile this command:
javac -cp '.:thing-1.0.0-SNAPSHOT-standalone.jar' HelloWorldApp.java
Compilation succeeds, but the program does not run on startup (ClassNotFoundException). The second form of calling foo directly, like foo (5), doesn't even compile. I've also tried it with and without a "static" declaration in the: gen-class.
+3
source to share