I want to call Clojure code compiled to a class from Java.
Clojure class:
(ns clj.core)
(gen-class
:name de.wt.TestClj
:state state
:init init
:prefix "-"
:main false
:methods [[setValue [String] void]
[getValue [] String]])
(defn -init []
[[] (atom {:value ""})])
(defn -setValue [this val]
(swap! (.state this) assoc :value val))
(defn -getValue [this]
(@(.state this) :value))
Compiled with lein uberjar
and copied the output -standalone.jar into the Java project under subdirs de/wt
.
The .java file:
import de.wt.TestClj;
class CljTest {
public static void main(String args[]) {
TestClj test = new TestClj();
System.out.println("Pre: " + test.getValue());
test.setValue("foo");
System.out.println("Post: " + test.getValue());
}
}
Now when I try to compile
~/testbed/cljava/java % tree [1 14:44:53]
.
├── CljTest.java
├── de
│ └── wt
│ └── TestClj.jar
└── TestClj.jar
2 directories, 3 files
~/testbed/cljava/java % javac -cp ./:./de/wt/TestClj.jar CljTest.java
CljTest.java:1: error: package de.wt does not exist
import de.wt.TestClj;
^
CljTest.java:5: error: cannot find symbol
TestClj test = new TestClj();
^
symbol: class TestClj
location: class CljTest
CljTest.java:5: error: cannot find symbol
TestClj test = new TestClj();
^
symbol: class TestClj
location: class CljTest
3 errors
What scheme do I need to follow when naming files/packages, creating directories and setting class paths?