尝试使用gen-class创建的类时ClassNotFoundException

时间:2017-09-08 16:31:40

标签: clojure

我的代码:

(ns model.document
  (:gen-class
    :name model.document
    :implements java.io.Serializable
    :state "state"
    :init "init"
    :constructors {[String String String] []}
    :methods [[getContent [] String]
              [getTitle [] String]
              [getUrl [] String]]))

(defn -init [content title url]
  [[] (atom {:content content
             :title title
             :url url})])

(defn- get-field [this k]
  (@(.state this) k))

(defn getContent [this]
  (get-field this :content))

(defn getTitle [this]
  (get-field this :title))

(defn getUrl [this]
  (get-field this :url))

它的使用:

(ns classification-server.classifier
  (:require [model.document :refer :all]))

(new model.document "my-content" "my-title" "my-url")

我得到了无益的帮助:

Caused by: java.lang.ClassNotFoundException: model.document, compiling:(classification_server/classifier.clj:13:12)

请帮助我。你是我唯一的希望......

1 个答案:

答案 0 :(得分:5)

您发布的gen-class命名空间无法编译,因为:implements规范需要符号向量而不是符号。如果您将该行更改为

:implements [java.io.Serializable]

您将能够编译(并实例化)该类 - 但是,它将不起作用,因为您的gen-class规范存在其他问题,例如缺少前缀函数(-getContent等)。

我建议你阅读gen-class documentation并简化。{ 进一步的问题。