clojure - ClassNotFoundException on use of another ns -
as simple question is, can't seem find right way different namespaces in same directory validly refer 1 another. have 2 files:
project_root/src/babbler/core.clj:
(ns babbler.core (:gen-class) (use '[clojure.string :only (join split)])) (defn foo [] "foo") and project_root/src/babbler/bar.clj:
(ns babbler.bar) (use [babbler.core :as babble]) this file contains main method, specified in project.clj via :main babbler.bar
my entire structure generated counterclockwise, with default leiningen template.
the result of running lein repl this:
exception in thread "main" java.lang.classnotfoundexception: babbler.core, compiling:(babbler/bar.clj:3:1) @ clojure.lang.compiler.analyze(compiler.java:6380) @ clojure.lang.compiler.analyze(compiler.java:6322) @ clojure.lang.compiler$vectorexpr.parse(compiler.java:3024) @ clojure.lang.compiler.analyze(compiler.java:6363) @ clojure.lang.compiler.analyze(compiler.java:6322) (...)
your use should inside definition of namespace:
(ns babbler.bar (use [babbler.core :as babble])) in fact use discouraged, may want write as:
(ns babbler.bar (:require [babbler.core :as babble :refer [foo]])) that way can call function f babbler.core namespace babble/f, , can call foo directly. in addition, file has information foo comes or else won't need go searching it.
Comments
Post a Comment