我正在测试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
我应该做些什么?
答案 0 :(得分:5)
在这里查看我的答案,这几乎是我想要的:https://stackoverflow.com/a/14014153/6264
提示: