title: ClassNotFoundException when using instance? on a defrecord type in Clojure
body: <p>I've written a function that selects only the keys of a map that are named in a specific <a href="https://github.com/Prismatic/schema" rel="nofollow">schema</a>:</p>
  
  <pre><code>(ns foo.schema
    (:require [schema.core :as s]))
  
  (defn select-schema
    "Given a schema and a map m, selects only the keys of m that are named in the schema."
    [m schema]
    (let [optional? #(instance? schema.core.OptionalKey %)
          wildcard? #(= s/Keyword %)]
      (if (some wildcard? (keys schema))
        m  ; the schema allows any keyword as a key, so just return the map
        (let [ks (-&gt;&gt; schema keys (map #(if (optional? %) (:k %) %)))]
          (select-keys m ks)))))
  </code></pre>
  
  <p>This works just fine in my unit tests:</p>
  
  <pre><code>(testing "Required key and wildcard"
      (let [schema {:foo s/Str, s/Keyword s/Any}]
        (is (= {:foo "Yup", :bar 42, :baz true} (select-schema {:foo "Yup", :bar 42, :baz true} schema)))
        (is (= {:foo "Yup", :bar 42} (select-schema {:foo "Yup", :bar 42} schema)))
        (is (= {:foo "Yup"} (select-schema {:foo "Yup"} schema)))))
  </code></pre>
  
  <p>However, when I use <code>foo.schema/select-schema</code> in a completely separate project (i.e. <code>lein install</code> in my foo project to build a jar and stick it in my <code>~/.m2/repository</code> and name it as a dependency), I get a <code>ClassNotFoundException</code>:</p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError, compiling:(insurrection/test/handler.clj:1:1)
      at clojure.lang.Compiler.load(Compiler.java:7142)
      ...
  Caused by: java.lang.ExceptionInInitializerError
      at foo.schema__init.load(Unknown Source)
      at foo.schema__init.&lt;clinit&gt;(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      ...
  Caused by: java.lang.ClassNotFoundException: schema.core.OptionalKey
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      ...
  </code></pre>
  
  <p>I looked at the Prismatic Schema source and found that <code>OptionalKey</code> is a defrecord type. A little Googling revealed that defrecord generates a Java class, which sometimes needs to be imported after requiring the namespace that defines it, but trying to do that in the project  that contains <code>foo.schema</code> doesn't make any difference: it works in the unit tests, but doesn't work in the other project that uses <code>foo</code> as a dependency.</p>