我想调用从 Java 编译为类的 Clojure 代码。
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))
编译lein uberjar
输出 -standalone.jar 并将其复制到 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
在命名文件/包、创建目录和设置类路径时,我需要遵循什么方案?