3

Whenever I try to call clojure from java I get a class not found exception. I can call the Clojure from another Clojure class. What am I doing wrong?

Update:

I finally figured it out. I should have used forward slashes instead of "." in RT.load:

RT.load("namespace/file_name", true);

asked Apr 25, 2011 at 14:09
1

1 Answer 1

5

A lot of old outdated tutorials talk about using RT.load to run clojure code from java. this is left over from the stone age and no longer necessasary.

see this SO question

here is a teaser from that question showing the generally accepted java side:

/* Thanks clartaq for this example */
import com.domain.tiny;
public class Main {
 public static void main(String[] args) {
 System.out.println("(binomial 5 3): " + tiny.binomial(5, 3));
 System.out.println("(binomial 10042, 111): " + tiny.binomial(10042, 111));
 }
}

it should just look like normal java code. You're java code does not need to look any different just because the class it's calling happens to have been written in Clojure.

answered Apr 25, 2011 at 18:44
Sign up to request clarification or add additional context in comments.

5 Comments

nice... I hadn't realised you could do that!!
But doesn't this require that you run "compile" every time on the clojure code? Kind of loses the dynamic benfits?
yes, if you want to compile the java code once, and then work on the clojure code without recompiling the clojure code between runs then this method is not very well suited. Typically the java code and clojure code are build together by maven or maven+leiningen so I dont get to see this distinction very often.
how java and clojure can be build together by maven? if there are any static dependencies between them (or what is worst, the cycles) then i can't force maven to do it, see: stackoverflow.com/questions/14110657/…
This answer is really old now, and things have improved a lot. Leiningen now handles building mixed source projects nicely and the zi and clojure-maven maven plugins works nicely for building maven3 projects.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.