clojure/clojure · error · FileNotFoundException

Could not locate Clojure resource on classpath:

Error message

Could not locate Clojure resource on classpath: 

What it means

RT.loadResourceScript locates a .clj resource on the classpath by name; when the resource stream is null and failIfNotFound is true, it throws FileNotFoundException with this message. It means the requested Clojure source file is not present anywhere on the classpath.

Solutions

  1. Verify the file exists on the classpath at the path matching the namespace (dashes become underscores).
  2. Check the classpath (java -cp, :source-paths, :resources-paths) includes the directory/jar containing the file.
  3. Fix typos in the load/require name.
  4. Rebuild the jar if the .clj was recently added but not packaged.

Example fix

// before
(load "my-ns/util") ; file my_ns/util.clj not on classpath
// after
;; ensure src/my_ns/util.clj exists and src is on the classpath, then:
(require '[my-ns.util])
Defensive patterns

Strategy: validation

Validate before calling

(when (nil? (clojure.java.io/resource "foo/bar.clj"))
  (throw (ex-info "Resource missing from classpath" {:resource "foo/bar.clj"})))

Try / catch

(try (load "foo/bar") (catch java.io.FileNotFoundException e (println "Not on classpath:" (.getMessage e))))

Prevention

When it happens

Trigger: Calling RT.loadResourceScript / clojure.core.load with a name whose corresponding resource (e.g. foo/bar.clj) does not exist on the classpath, typically via (require 'foo.bar) or (load "foo/bar") with a typo or missing dependency.

Common situations: Namespace name typo, source file missing from the built jar, wrong classpath configuration, underscore/dash mismatch between namespace and filename, resource excluded by build tool resource filters.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of clojure/clojure@f3b143341d (2026-09-09). Data as JSON: /api/errors/782c8283e6a5aa10. Report an issue: GitHub.

Appendix: source

Thrown at src/jvm/clojure/lang/RT.java:384

public static void loadResourceScript(Class c, String name) throws IOException{
	loadResourceScript(c, name, true);
}

public static void loadResourceScript(Class c, String name, boolean failIfNotFound) throws IOException{
	int slash = name.lastIndexOf('/');
	String file = slash >= 0 ? name.substring(slash + 1) : name;
	InputStream ins = resourceAsStream(baseLoader(), name);
	if(ins != null) {
		try {
			Compiler.load(new InputStreamReader(ins, UTF8), name, file);
		}
		finally {
			ins.close();
		}
	}
	else if(failIfNotFound) {
		throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + name);
	}
}

static public long lastModified(URL url, String libfile) throws IOException{
	URLConnection connection = url.openConnection();
	try {
		if (url.getProtocol().equals("jar"))
			return ((JarURLConnection) connection).getJarFile().getEntry(libfile).getTime();
		else
			return connection.getLastModified();
	}
	finally {
		InputStream ins = connection.getInputStream();
		if (ins != null)
			ins.close();
	}
}

View on GitHub (pinned to f3b143341d)