クラスにコンパイルされた Clojure コードを Java から呼び出したい。
Clojure クラス:
(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))
出力 -standalone.jar をコンパイルしてlein uberjar
、 subdirs の下の Java プロジェクトにコピーしましたde/wt
。
.java ファイル:
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());
}
}
今、コンパイルしようとすると
~/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
ファイル/パッケージの命名、ディレクトリの作成、およびクラスパスの設定を行う際には、どのスキームに従う必要がありますか?