Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Java complain that namespace is not found?

I am trying to set up a lein build environment on Windows 7 haven copied files from a successful build environment on Linux. I have maven and the jdk installed along with lein.

HOME points to c:\Users\cnorton where the maven directories are located.

I get this error when trying to run lein repl or lein compile, and cannot figure out what I am doing wrong.

Caused by: java.lang.Exception: namespace 'repl-test.core' not found after loading '/repl_test/core'

Here is project.clj

(defproject repl-test "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [clojure-csv/clojure-csv "1.2.4"]
                 [org.clojure/tools.cli "0.1.0"]
                 [clj-http "0.1.3"]]
   :aot [repl-test.core]
   :main repl-test.core)

Here is the first part of src/repl_test/core.clj

(ns repl-test.core
  (:gen-class)
  (:use clojure.contrib.command-line)
  (:require [clojure.contrib.string :as cstr])
  (:require [clojure.contrib.trace :as ctr])
  (:require [clojure.string :as sstr])
  (:use clojure-csv.core))

I would be super helpful if someone could post as an answer a project.clj and the header of a core.clj that allows the project to be a main.

like image 403
octopusgrabbus Avatar asked Oct 04 '12 00:10

octopusgrabbus


1 Answers

I would avoid "-" in your folder names and namespaces, it is actually converted to "_" but not in all places.

The following may or may not work for you. I got your skeleton project working with:

(defproject st1 "1.0.0-SNAPSHOT"
:description "TODO: add summary of your project"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [clojure-csv/clojure-csv "1.2.4"]
                 [org.clojure/tools.cli "0.1.0"]
                 [clj-http "0.1.3"]]
                 :aot [repl_test.core]
                 :main repl_test.core)

The same clj file as you have:

 (ns repl_test.core
  (:gen-class)
  (:use clojure.contrib.command-line)
  (:require [clojure.contrib.string :as cstr])
  (:require [clojure.contrib.trace :as ctr])
  (:require [clojure.string :as sstr])
  (:use clojure-csv.core))

And I renamed the folder repl-test to repl_test with underscore.

Then

 lein compile

and

 lein run

By curiosity, I also looked at clojure-csv, and they are using "-" everywhere, except in the folder name, so may have luck copying what they did.

Also, quoting another SO question on clojure namespaces:

"Also note that you musn't use the underscore in namespace names or the hyphen in filenames and wherever you use a hyphen in a namespace name, you must use an underscore in the filename (so that the ns my.cool-project is defined in a file called cool_project.clj in a directory called my)."

And from the Clojure Programming Wiki section on java packages: "Clojure respects Java naming conventions for directories and files, but Lisp naming conventions for namespace names. So a Clojure namespace com.my-app.utils would live in a path named com/my_app/utils.clj. Note especially the underscore/hyphen distinction."

like image 114
Nicolas Modrzyk Avatar answered Oct 20 '22 16:10

Nicolas Modrzyk