问题
I am trying to access some of my clojure functions in my Java code (I am using Eclipse and CounterClockWise). Firstly, I was not sure how to do it? But then I found some answer here.
I am using clojure.lang.RT package
for calling .clj
files in my Java code. While naming namespaces, .clj
files proper conventions has been followed like ns test.clojure.core
is in test.clojure
package where-in core is .clj
file. Also upon following some information, I have added java-source-path (i.e. java-source-path src/test/java
) and source-path (i.e. source-path src/test/clojure
) in my project.clj
.
But, when I run my Java file following error is given - a) Could not locate Clojure resource on classpath
b) Attempting to call unbound fn
.
Please if anyone in community could help me (assuming I am absolute beginner) through detailed procedure or tutorial I would be grateful, as only information I could get (for using clojure.lang.RT
) is very little.
Looking forward to get a complete answer to end my frustration.
回答1:
I guess you are using RT.loadResourceScript
which is causing the proble.
You can try out something like this:
//Load the namespace
RT.var("clojure.core","eval").invoke(RT.var("clojure.core","read-string").invoke("(use 'test.clojure.core)"));
//Find a function in namespace
IFn fn = (IFn)RT.var("test.clojure.core","hello");
//Call that function
fn.invoke();
来源:https://stackoverflow.com/questions/15116334/could-not-locate-clojure-resource-on-classpath