1

There are two directories in a clojure project - src/ and test/. There's a file my_methods.clj in the src/calc/ directory which starts with

(ns calc.my_methods...).

I want to create a test file for it in test directory - test/my_methods-test.clj

(ns test.my_methods-test
  (:require [calc.my_methods])
  (:use clojure.test))

In the $CLASSPATH there are both project root directory and src/ directory. But the exception is still

"Could not locate calc/my_methods__init.class or calc/my_methods.clj on classpath". What is the problem with requiring it in the test file?

echo $CLASSPATH gives this:

~/project:~/project/src
Sergey
  • 11,548
  • 24
  • 76
  • 113

2 Answers2

4

First, I'd suggest using Leiningen to manage the CLASSPATH for you. Second, I find that the ~ character to stand in for my home directory never works in the CLASSPATH context - I have to specify the absolute path, no aliasing (e.g. /Users/colin/path/to/project). Third, it's conventional to have src and test on the classpath, but not the root level of a project.

trptcolin
  • 2,320
  • 13
  • 16
  • +1 for suggesting leiningen. It's the de facto standard build/run/pacakage tool for Clojure and it'll make your life a million times simpler. – Gert Jun 06 '12 at 10:44
1

Be very careful about your use of dashes and underscores in file names and namespaces. If you don't get the naming conventions right, this can be the source of a lot of confusion. See https://stackoverflow.com/a/2223369/32174, point 2. And as @trptcolin mentions, use Leiningen.

Community
  • 1
  • 1
Julien Chastang
  • 17,592
  • 12
  • 63
  • 89