我正在测试 Clojure/Java 互操作。我创建了一个新的 Leiningen 项目并创建了这个 project.clj 文件,其中包含一些我将使用的依赖项:
(defproject kente "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring-jetty-adapter "1.0.0-RC1"]
[compojure "0.6.5"]
[hiccup "0.3.7"]
[cheshire "5.0.1"]]
:java-source-paths ["src/java"]
:plugins [[lein-ring "0.8.2"]]
:ring {:handler kente.core/application}
:main kente.core)
我还包括了“java-source-paths”列表,并将 hello.java 文件放入 src/java 目录,如下所示:
public class hello {
private String msg = "Hello World";
public String sayHello() {
return this.msg;
}
}
然后我从模板创建了这个 core.clj 文件:
(ns kente.core
(:require [java/hello]))
(defn application
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(defn -main [] (application "Say: "))
正如你所看到的,我什至没有在应用程序函数中使用 hello java 类,我只是需要它,但是当我在终端中运行“lein jar”时,我得到了这个堆栈跟踪:
$ lein jar
Compiling kente.core
Exception in thread "main" java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: , compiling:(core.clj:1)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3387)
at clojure.lang.Compiler.compile1(Compiler.java:7035)
at clojure.lang.Compiler.compile1(Compiler.java:7025)
at clojure.lang.Compiler.compile(Compiler.java:7097)
at clojure.lang.RT.compile(RT.java:387)
at clojure.lang.RT.load(RT.java:427)
at clojure.lang.RT.load(RT.java:400)
at clojure.core$load$fn__4890.invoke(core.clj:5415)
at clojure.core$load.doInvoke(core.clj:5414)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5227)
at clojure.core$compile$fn__4895.invoke(core.clj:5426)
at clojure.core$compile.invoke(core.clj:5425)
at user$eval7.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.eval(Compiler.java:6477)
at clojure.core$eval.invoke(core.clj:2797)
at clojure.main$eval_opt.invoke(main.clj:297)
at clojure.main$initialize.invoke(main.clj:316)
at clojure.main$null_opt.invoke(main.clj:349)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath:
at clojure.lang.RT.load(RT.java:432)
at clojure.lang.RT.load(RT.java:400)
at clojure.core$load$fn__4890.invoke(core.clj:5415)
at clojure.core$load.doInvoke(core.clj:5414)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5227)
at clojure.core$load_lib.doInvoke(core.clj:5264)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$require.doInvoke(core.clj:5381)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at kente.core$loading__4784__auto__.invoke(core.clj:1)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3382)
... 26 more
我应该做些什么不同的事情?