6

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.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131

1 Answers1

7

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."

Community
  • 1
  • 1
Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
  • I tried your suggestion, and it compiled with the same error. I am still a little confused about project.clj project names, core.clj ns names, and folder names. Wouldn't :aot also refer to repl_test, and wouldn't `st1` be referenced somewhere? – octopusgrabbus Oct 04 '12 at 13:08
  • I think it would be helpful to explain why using `-` or `_` in namespaces can cause problems. – Matt Fenwick Oct 04 '12 at 17:43
  • @MattFenwick clojure-csv has a dash in it. How is it built? That is on which platform? I'll go try to find out. – octopusgrabbus Oct 04 '12 at 19:07
  • Just renaming namespace didn't work here. But, creating a new project without "-" in the name solved my problem. Hope this helps somebody too. – guijob Aug 28 '16 at 23:06