Clojure 扩展协议导致NoClassDefFoundError

Clojure 扩展协议导致NoClassDefFoundError,clojure,Clojure,与我的有关,但不同 我试图用deftype实现clj-time.core.DateTimeProtocol。当类型签名冲突时,我使用的是这个而不是defrecord(请参阅) 我有两个文件。第一个是实现,第二个是测试。如您所见,测试文件所做的只是requireing实现文件。很抱歉代码转储,但这是最低工作版本: date.clj: (ns util.date (:require [clj-time.core :as clj-time]) (:require [clj-time.core

与我的有关,但不同

我试图用
deftype
实现
clj-time.core.DateTimeProtocol
。当类型签名冲突时,我使用的是这个而不是
defrecord
(请参阅)

我有两个文件。第一个是实现,第二个是测试。如您所见,测试文件所做的只是
require
ing实现文件。很抱歉代码转储,但这是最低工作版本:

date.clj:

(ns util.date
  (:require [clj-time.core :as clj-time])
  (:require [clj-time.core :refer [DateTimeProtocol]])
  (:gen-class))

(defprotocol IWeirdDate
  (as-date [this]))

(deftype WeirdDate [year month day]
  IWeirdDate
  (as-date [this] (clj-time/date-time year month day)))

(extend-protocol DateTimeProtocol
    WeirdDate
    (year [this] (clj-time/year (as-date this)))
    (month [this] (clj-time/month (as-date this)))
    (day [this] (clj-time/day (as-date this)))
    (day-of-week [this] (clj-time/day-of-week (as-date this)))
    (hour [this] (clj-time/hour (as-date this)))
    (minute [this] (clj-time/minute (as-date this)))
    (sec [this] (clj-time/sec (as-date this)))
    (second [this] (clj-time/second (as-date this)))
    (milli [this] (clj-time/milli (as-date this)))
    (after? [this that] (clj-time/after? (as-date this) that))
    (before? [this that] (clj-time/before? (as-date this) that)))

(defn weird-date [y m d] (WeirdDate. y m d))

(def x (WeirdDate. 1986 5 2))
(def y (clj-time/date-time 2014 5 2))

(prn "Loaded OK source" x y)
date_test.clj

(ns util.date-test
  (:require [clojure.test :refer :all]
            [util.date :refer [weird-date]])
  (:require [clj-time.core :as clj-time]))

(def x (weird-date 1986 5 2))
(def y (clj-time/date-time 2014 5 2))

(prn "Loaded OK in test" x y)
这与
lein测试
lein检查
lein编译
等有关

奇怪的是,源文件似乎工作正常:

"Loaded OK source" #<WeirdDate util.date.WeirdDate@7e793d7a> #<DateTime 2014-05-02T00:00:00.000Z>
Exception in thread "main" java.lang.NoClassDefFoundError: clj_time/core/DateTimeProtocol
因此,看起来简单地从一个名称空间引用这个协议就可以阻止另一个名称空间加载,而这个名称空间甚至没有提到它


什么?

您使用的是什么版本的Clojure和clj time?您如何构建/运行该项目?这对我来说适用于使用CLJTime0.8.0和所有最新的Clojure版本。Lein2.3.3,Clojure0.8.8。奇怪的是,它看起来像是在名称空间中工作的,当我试图从另一个名称空间访问它时,我会出错。我试图得到一些可复制的东西。(实际上我用相同的
deftype
实现了Java接口和Clojure协议)好的@Alex,我刚刚用一些可复制的东西重新写了这个问题。实际上这看起来可能是
aot
gen class
的组合。它现在工作了我已经清除了我的
目标
目录。。。
"Loaded OK source" #<WeirdDate util.date.WeirdDate@3f19c149> #<DateTime 2014-05-02T00:00:00.000Z>
"Loaded OK source" #<WeirdDate util.date.WeirdDate@5c797bc6> #<DateTime 2014-05-02T00:00:00.000Z>
"Loaded OK in test" #<WeirdDate util.date.WeirdDate@19c6a644> #<DateTime 2014-05-02T00:00:00.000Z>