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);

yazz.com
  • 57,320
  • 66
  • 234
  • 385
  • possible duplicate of [Calling clojure from java](http://stackoverflow.com/questions/2181774/calling-clojure-from-java) – om-nom-nom Feb 27 '13 at 11:24

1 Answers1

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.

Community
  • 1
  • 1
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • nice... I hadn't realised you could do that!! – mikera Apr 25 '11 at 21:34
  • But doesn't this require that you run "compile" every time on the clojure code? Kind of loses the dynamic benfits? – yazz.com Apr 26 '11 at 12:03
  • 1
    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. – Arthur Ulfeldt Apr 26 '11 at 17:41
  • 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: http://stackoverflow.com/questions/14110657/java-mixed-with-clojure-in-maven-and-eclipse – piotrek Jan 01 '13 at 14:27
  • 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. – Arthur Ulfeldt Jan 02 '13 at 20:57