{"record":{"id":"782c8283e6a5aa10","repo":"clojure/clojure","slug":"could-not-locate-clojure-resource-on-classpath","errorCode":null,"errorMessage":"Could not locate Clojure resource on classpath: ","messagePattern":"Could not locate Clojure resource on classpath: ","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/jvm/clojure/lang/RT.java","lineNumber":384,"sourceCode":"\npublic static void loadResourceScript(Class c, String name) throws IOException{\n\tloadResourceScript(c, name, true);\n}\n\npublic static void loadResourceScript(Class c, String name, boolean failIfNotFound) throws IOException{\n\tint slash = name.lastIndexOf('/');\n\tString file = slash >= 0 ? name.substring(slash + 1) : name;\n\tInputStream ins = resourceAsStream(baseLoader(), name);\n\tif(ins != null) {\n\t\ttry {\n\t\t\tCompiler.load(new InputStreamReader(ins, UTF8), name, file);\n\t\t}\n\t\tfinally {\n\t\t\tins.close();\n\t\t}\n\t}\n\telse if(failIfNotFound) {\n\t\tthrow new FileNotFoundException(\"Could not locate Clojure resource on classpath: \" + name);\n\t}\n}\n\nstatic public long lastModified(URL url, String libfile) throws IOException{\n\tURLConnection connection = url.openConnection();\n\ttry {\n\t\tif (url.getProtocol().equals(\"jar\"))\n\t\t\treturn ((JarURLConnection) connection).getJarFile().getEntry(libfile).getTime();\n\t\telse\n\t\t\treturn connection.getLastModified();\n\t}\n\tfinally {\n\t\tInputStream ins = connection.getInputStream();\n\t\tif (ins != null)\n\t\t\tins.close();\n\t}\n}\n","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/clojure/clojure/blob/f3b143341d6efc6428b523b2eaa099a6cc99156e/src/jvm/clojure/lang/RT.java#L366-L402","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the file exists on the classpath at the path matching the namespace (dashes become underscores).","Check the classpath (java -cp, :source-paths, :resources-paths) includes the directory/jar containing the file.","Fix typos in the load/require name.","Rebuild the jar if the .clj was recently added but not packaged."],"exampleFix":"// before\n(load \"my-ns/util\") ; file my_ns/util.clj not on classpath\n// after\n;; ensure src/my_ns/util.clj exists and src is on the classpath, then:\n(require '[my-ns.util])","handlingStrategy":"validation","validationCode":"(when (nil? (clojure.java.io/resource \"foo/bar.clj\"))\n  (throw (ex-info \"Resource missing from classpath\" {:resource \"foo/bar.clj\"})))","typeGuard":null,"tryCatchPattern":"(try (load \"foo/bar\") (catch java.io.FileNotFoundException e (println \"Not on classpath:\" (.getMessage e))))","preventionTips":["Check (io/resource path) resolves before load.","Keep namespace names dash-separated and file names underscore-separated.","Verify jar packaging includes .clj sources (exclusions in build config are a common cause)."],"tags":["clojure","classpath","resource-not-found","io"],"backgroundTag":"file-not-found","analyzedSha":"f3b143341d6efc6428b523b2eaa099a6cc99156e","analyzedAt":"2026-09-09T12:04:58.961Z","contentChangedAt":"2026-09-09T12:04:58.961Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}