Leslie Binbin
Leslie Binbin

Reputation: 23

About Integrate Clojure into springboot framework

I'm currently trying to integrate clojure into gradle springboot project, even though it works, I do have to use RT.loadClassForName("au.edu.uq.core"); before the Clojure.var could access the function, if I comment the RT.loadClassForName("au.edu.uq.core");, there will be an error like:

Exception in thread "main" java.lang.IllegalStateException: Attempting to call unbound fn: #'au.edu.uq.core/hello-from-clojure.

But in the build.gradle I already include classes.dependsOn compileClojure.

There are screenshots of build.gradle, Main Java Class and the clojure namespace. This is a tiny demo project for me to learn gradle, any suggestions to make this build process more elegant?

Starting script is ./gradlew bootRun and ./gradlew run

//This is the Java Main Class enter image description here

//This is the clojure namespace enter image description here

//This is the build.gradle enter image description here

Upvotes: 0

Views: 681

Answers (1)

Denis Fuenzalida
Denis Fuenzalida

Reputation: 3346

From what I got from the screenshot of the Main class, it seems you are using Clojure.lang.RT to load your function, while the official reference documentation suggests otherwise:

Functions in clojure.core are automatically loaded. Other namespaces can be loaded via require:

IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("clojure.set"));

My suggestion would be to try something like:

IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("au.edu.uq.core"));
IFn helloFunction = Clojure.var("au.edu.uq.core", "hello-from-clojure");
helloFunction.invoke();

Upvotes: 1

Related Questions