I've followed this tutorial to call Clojure from Java in Eclipse by using Leiningen. I want to code my game's AI in Clojure and do the rest in LibGDX for Android OS.
Once I have finished the Clojure side, I use the lein command to package it in a jar file (#lein compile, #lein run, #lein uberjar).
I add the jar file with right click on project > Properties > Java Build Path > Libraries > Add External JARs... > myai-0.1.0-SNAPSHOT-standalone.jar.
My problem occurs when I execute the game.
import myai.*;
public class Stack extends Actor {
...
public void draw(SpriteBatch batch, float parentAlpha) {
System.out.println("Binomial = " + core.binomial(5, 15));
}
...
}
I receive this error:
12-26 00:27:01.570: I/dalvikvm(8384): Could not find method myai.core.binomial, referenced from method my.package.Stack.draw
12-26 00:27:01.570: E/AndroidRuntime(2281): FATAL EXCEPTION: GLThread
12-26 00:27:01.570: E/AndroidRuntime(2281): java.lang.NoClassDefFoundError: myai.core
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.Stack.draw(Stack.java:297)
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.GameScreen.render(GameScreen.java:146)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.Game.render(Game.java:46)
12-26 00:27:01.570: E/AndroidRuntime(2281): at my.package.MyGame.render(MyGame.java:23)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
12-26 00:27:01.570: E/AndroidRuntime(2281): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)
I really don't know why it happens because I have followed all steps in the tutorial.
These are my clojure files:
project.clj
(defproject myai "0.1.0-SNAPSHOT"
:description "AI for my game"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
:aot [myai.core]
:main myai.core)
core.clj
(ns myai.core
(:gen-class
:name myai.core
:methods [#^{:static true} [binomial [int int] double]])
)
(defn binomial
"Calculate the binomial coefficient."
[n k]
(let [a (inc n)]
(loop [b 1
c 1]
(if (> b k)
c
(recur (inc b) (* (/ (- a b) b) c))))))
(defn -binomial
"A Java-callable wrapper around the 'binomial' function."
[n k]
(binomial n k))
(defn -main
[& args]
(println "My Game Artificial Intelligence")
(println (str "(binomial 5 3): " (binomial 5 3)))
)
Thanks in advance! :)
EDIT: It doesn't work either in Ubuntu with command line commands.
What a stupid mistake... I forgot to check the Clojure .jar file in Properties > Java Build Path > Order and Export tab, so it wasn't added to the classpath at compiling time.