Everything about your project structure and project.clj looks entirely normal.
What if I want to load src/utils/general.clj:
This is almost always done through arequire
oruse
expression. While it is possible to load a file withload-file
this requires you to specify the path (relative to where you started the JVM) to the file.load
loads it relative to the class-path though in practice these are almost never used when the files being loaded are part of the project. In that case you can simplyrequire
them.I'd like to be able to require or use these source files from other source files:
The expected way of doing this is to put a(:require [popco.core.acme :as acme])
statement in the ns form at the top of the namespace that wants to use functions from that namespace.How can I reference the functions in general.clj from inside acme.clj:
(ns popco.core.acme
(:require [utils.general :refer [function1 function2] :as general))I think the answer might be to add entries to the sequence after :source-paths in project.clj:
You will most likely never need to put anything there.require
anduse
are the appropriate tool for this. They will already be able to find all the files under /src/ because those files will be in the classpath when the leiningen starts java. You can see the class path used with thelein classpath
function.
ps: You can also call require
and use
as functions (form the REPL for instance), though doing this in the ns form is generally preferred.