java - How do I set up classes in a Lein project? -
i ran lein new app hm
, in hm/src/hm
edited core.clj
be:
(ns hm.core (:gen-class) (:use [hm.hashmap])) (defn -main [] (def j (new hm.hashmap)) (-add j "foo" "bar") (println j))
and hashmap.clj
be:
(ns hm.hashmap (:gen-class :methods [[hashmap [] java.util.hashmap] [add [string string]]])) (defn -hashmap [] (def h (new java.util.hashmap)) h) (defn -add [this key value] (. put key value) this)
the goal make wrapper around hashmap can understand clojure , how ties java. i'm new clojure. however, when compile this, lot of classnotfoundexception in hashmap.clj
. how can make work?
note: direct answer question. don't recommend learn clojure way.
you need compile classes before can run them. in project.clj add map:
:aot [hm.hashmap]
then need run lein compile
in order compile classes. should see output saying hm.hashmap
class compiled. after run lein run
invoke "main "function in hm.core
.
i removed :methods
part of gen-class because you're defining them below, , causing weird java.lang.,
error. you're going run other errors, should enough passed issue.
Comments
Post a Comment