0
votes

I'm new to CLojure and running a simple piece of code to test out the data.csv package. I'm using Leiningen and running on Windows 7 (having no choice). Leiningen was installed with the Windows installer. JDE 1.7 is installed and available.

Here is my source file:

(ns testcsv.core
  (:gen-class))

(:require [clojure.data.csv :as csv])
(:require [clojure.java.io :as io]))


(defn add-data-store [] 
  (let [csv-records (csv/parse-csv (slurp "census_data_growth.csv")) ;field-names (nthnext (second csv-records) 3)
        ]
    ;; more code to come when this works
  ))

Here is my project.clj:

(defproject testcsv "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]
                  [org.clojure/data.csv "0.1.2"]]
  :main ^:skip-aot powernoodle1.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

I've run lein deps and lein classpath and lein compile in many combinations. The error from lein compile is:

java.lang.ClassNotFoundException: clojure.data.csv, compiling:(testcsv/core.clj:4:1)

Which would seem to imply that it is not finding the data.csv jar, which would in turn seem to imply a classpath problem.

Is there a step I've missed?

I've also heard that Leiningen has classpath issues on Windows. Does anyone have specifics?

1
the ClassNotFoundException is a side effect of using require wrong, so Clojure thinks the namespace you ask for is a class it can't find. See my answer for details of how to use require properly.noisesmith

1 Answers

4
votes

:require needs to be part of your ns declaration. Also the declaration should have only one :require clause.

(ns testcsv.core
  (:gen-class)
  (:require [clojure.data.csv :as csv]
            [clojure.java.io :as io]))

require (the function, not the keyword) can be used outside an ns declaration, mostly for repl usage. It would look like (require '[clojure.data.csv :as csv]).

Because of an implementation detail of keywords being overloaded to be usable as functions to perform lookup, (:foo x) is never an error if :foo is some keyword, and x exists, no matter what x is.