0
當我在我的clojure項目中導入自定義java類時,我得到了ClassNotFoundException
。lein自定義java類未找到異常
;project.clj
(defproject subclass "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]]
:java-source-paths ["src/java"]
:main subclass.core
:aot [subclass.core]
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
;src/subclass/core.clj
(ns subclass.core
(:gen-class
:extends BaseClass
:exposes-methods {greet pgreet})
(:import BaseClass)) ;This is being qualified as java.lang.BaseClass
(defn -main [& args])
//src/java/BaseClass.java
public class BaseClass {
public String greet() {
return "Hello from BaseClass";
}
}
當我運行lein repl
我收到以下錯誤:
Compiling subclass.core
java.lang.ClassNotFoundException: java.lang.BaseClass, compiling:(subclass/core.clj:1:1)
Exception in thread "main" java.lang.ClassNotFoundException: java.lang.BaseClass, compiling:(subclas
s/core.clj:1:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.analyze(Compiler.java:6625)
... snip ...
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: java.lang.Baseclass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
... snip ...
... 54 more
Compilation failed: Subprocess failed
的BaseClasss
越來越資格截至java.lang.BaseClass
其失敗。如何從src/java
引用BaseClass?謝謝。
'Baseclass'與'BaseClass'不是一回事。 –
對不起,更新了這篇文章。 – boring
Alan Thompson:謝謝,這很有用。 – boring