Lein run error: Could not locate clj_commons/fs__init.class

Hi,

I started an app with lein new app inv-clj.

The file src/inv_clj/core.clj has:

(ns inv-clj.core
  (:gen-class))

(require '[clj-commons.fs :as fs])

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

(fs/list-dir "./")
$ cat project.clj
(defproject inv-clj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [clj-commons/fs  "1.6.307"]
                 ]
  :main ^:skip-aot inv-clj.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all
                       :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})

The dependencies tree:

$ lein deps :tree
 [clj-commons/fs "1.6.307"]
   [org.apache.commons/commons-compress "1.20"]
   [org.tukaani/xz "1.8"]
 [nrepl "1.0.0" :exclusions [[org.clojure/clojure]]]
 [org.clojure/clojure "1.11.1"]
   [org.clojure/core.specs.alpha "0.2.62"]
   [org.clojure/spec.alpha "0.3.218"]
 [org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
 $ cat ~/.lein/profiles.clj
{:mirrors      {"central"  {:url  "https://repo.maven.apache.org/maven2/"}}}
{:user {:dependencies [slamhound  "1.5.5"]
        :aliases {"slamhound" ["run" "-m" "sl"]}}}
$ pwd
~/.m2/repository

$ find . -name '*fs*'
./fs
./fs/fs
./fs/fs/1.3.3/fs-1.3.3.pom
./fs/fs/1.3.3/fs-1.3.3.pom.sha1
./fs/fs/1.3.3/fs-1.3.3.jar
./fs/fs/1.3.3/fs-1.3.3.jar.sha1
./babashka/fs
./babashka/fs/0.5.23/fs-0.5.23.pom
./babashka/fs/0.5.23/fs-0.5.23.pom.sha1
./babashka/fs/0.5.23/fs-0.5.23.jar
./babashka/fs/0.5.23/fs-0.5.23.jar.sha1
./clj-commons/fs
./clj-commons/fs/1.6.307/fs-1.6.307.pom
./clj-commons/fs/1.6.307/fs-1.6.307.pom.sha1
./clj-commons/fs/1.6.307/fs-1.6.307.jar

Given all this, when doing lein run, there’s an error:

$ lein run
Execution error (FileNotFoundException) at inv-clj.core/eval165 (core.clj:4).
Could not locate clj_commons/fs__init.class, clj_commons/fs.clj or clj_commons/fs.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

What’s wrong and how to fix it?

The main issue is that clj-commons/fs is the group-id/artifact-id of the library, but it doesn’t mean that the namespace that you have to use is named the same way. If you look at the sources of the lib, you have to actualy (:require [me.raynes.fs :as fs]).

Also, when you have an ns form, you should use (:require [...]) inside that form instead of (require '[...]) outside the form.

Finally, and this is a minor point - according to the README of that library, it might be better to use thebabashka/fs library.

1 Like