Clojure java.lang.NoClassDefFoundError 调用时 clj-time/last-day-of-the-month

Clojure java.lang.NoClassDefFoundError when calling clj-time/last-day-of-the-month

我打电话

(clj-time.core/last-day-of-the-month 1999 2)

(clj-time.core/number-of-days-in-the-month 1999 2)

都抛出

java.lang.NoClassDefFoundError org/joda/time/DateTime$Property  org.joda.time.DateTime.dayOfMonth (DateTime.java:1971)

文档说:

(defn last-day-of-the-month
  ([^long year ^long month]
        (last-day-of-the-month- (date-time year month)))
  ([dt]
        (last-day-of-the-month- dt)))

(defn number-of-days-in-the-month
  (^long [^DateTime dt]
         (day (last-day-of-the-month- dt)))
  (^long [^long year ^long month]
         (day (last-day-of-the-month- (date-time year month)))))

我做错了什么?

谢谢!

以下是我的项目设置和依赖:


(defproject xxx "0.1.2-SNAPSHOT"
:description ""
:dependencies [[org.clojure/clojure "1.8.0"]

...
             [clj-time "0.11.0"]          

...)

我在项目 repl 中试过这个:

clj-time=> clj-time.core/last-day-of-the-month
#object[clj_time.core$last_day_of_the_month 0x6a86b560 "clj_time.core$last_day_of_the_month@6a86b560"]

以上结果来自我通过 ssh 通道连接到的 repl 服务器。

当我在本地项目文件夹运行lein repl时,可以得到正确的结果:

xxx.core=> (clj-time.core/last-day-of-the-month 2016 2)
#object[org.joda.time.DateTime 0x22a0534e "2016-02-29T00:00:00.000Z"]
xxx.core=> (clj-time.core/number-of-days-in-the-month 2016 2)
29

我是 Clojure 新手。这些信息有用吗?


重启repl后问题解决

非常适合我。

project.clj:

(defproject clj "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.9.0-alpha13"]
    [clj-time "0.12.0"]
  ]
  :java-source-paths ["/home/alan/xpr/src"]
  :main ^:skip-aot clj.core
  :target-path "target/%s"
  :profiles {:dev      {:dependencies [[org.clojure/test.check "0.9.0"]] }
             :uberjar  {:aot :all}}
)

主程序:

(ns clj.core
  (:require 
    [clj-time.core :as tm] 
  ))

(println :day  (tm/last-day-of-the-month 1999 2))

(println :days (tm/number-of-days-in-the-month 1999 2))

(defn -main [& args])

结果:

~/clj > lein run    
:day #object[org.joda.time.DateTime 0x61884cb1 1999-02-28T00:00:00.000Z]
:days 28