I'm just learning how to lein
, and I'd like to use from a Java source
a class created by deftype
in a Clojure source. This wasn't covered in the basic
tutorial and I can't get it to work properly.
The problem is that Java source can't import Clojure class, since it hasn't been compiled yet. And Clojure class isn't compiled, since compilation is aborted by the Java source.
I give a minimal example:
Create a new project with:
lein new app javafoo
Add to project.clj
:aot :all
:java-source-paths ["src/java"]
Put into src/javafoo/core.clj
:
(ns javafoo.core)
(deftype PPoint [x y])
Put into src/java/JavaFoo.java
:
package foo.java;
import javafoo.core.PPoint;
public class JavaFoo {
public static void main(String[] args) {
System.out.println("JavaFoo");
}
}
Try to compile
lein compile
It fails with package javafoo.core doesn't exist
.
So now I have to
:java-source-paths
:java-source-paths
It finally works. Is there a way to make it work from the start?
Add this line to your project.clj
:
:prep-tasks [["compile" "javafoo.core"] "javac"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With