{"record":{"id":"374d477a0bd88908","repo":"testcontainers/testcontainers-java","slug":"resource-with-path-resourcepath-could-not-be-found-on-any-of","errorCode":null,"errorMessage":"Resource with path ${resourcePath} could not be found on any of these classloaders: ${classLoadersToSearch}","messagePattern":"Resource with path (.+?) could not be found on any of these classloaders: (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/utility/MountableFile.java","lineNumber":158,"sourceCode":"            if (classLoader == null) {\n                continue;\n            }\n\n            URL resource = classLoader.getResource(resourcePath);\n            if (resource != null) {\n                return resource;\n            }\n\n            // Be lenient if an absolute path was given\n            if (resourcePath.startsWith(\"/\")) {\n                resource = classLoader.getResource(resourcePath.replaceFirst(\"/\", \"\"));\n                if (resource != null) {\n                    return resource;\n                }\n            }\n        }\n\n        throw new IllegalArgumentException(\n            \"Resource with path \" +\n            resourcePath +\n            \" could not be found on any of these classloaders: \" +\n            classLoadersToSearch\n        );\n    }\n\n    private static String unencodeResourceURIToFilePath(@NotNull final String resource) {\n        try {\n            // Convert any url-encoded characters (e.g. spaces) back into unencoded form\n            return URLDecoder\n                .decode(resource.replaceAll(\"\\\\+\", \"%2B\"), Charsets.UTF_8.name())\n                .replaceFirst(\"jar:\", \"\")\n                .replaceFirst(\"file:\", \"\")\n                .replaceAll(\"!.*\", \"\");\n        } catch (UnsupportedEncodingException e) {\n            throw new IllegalStateException(e);\n        }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/utility/MountableFile.java#L140-L176","documentation":"MountableFile.getClasspathResource resolves a classpath resource path using several classloaders. If no classloader can find the resource, it throws IllegalArgumentException listing the classloaders searched. This means the path given to MountableFile.forClasspathResource(...) does not point to an existing resource on the runtime classpath.","triggerScenarios":"MountableFile.forClasspathResource(\"some/file.txt\") (or forClasspathResource(path, offset)) where no file exists at that classpath-relative path — wrong path, missing leading handling, file not under src/main/resources or src/test/resources, or excluded from the built jar.","commonSituations":"Specifying an absolute filesystem path instead of a classpath path; file exists in src/test/java (not copied as a resource); resource filtered out by build config; running from an environment where the resource is in a different module's classpath; case mismatch in the resource name.","solutions":["Verify the resource exists on the runtime classpath: move it under src/test/resources (or src/main/resources) with the exact path used in the call.","Use the classpath-relative path (no leading slash ambiguity — try both) and check exact casing.","Confirm the build isn't excluding/filtering the resource and that the file is packaged in the jar you run tests from.","If you actually meant a filesystem file, use MountableFile.forHostPath instead."],"exampleFix":"// before\nMountableFile.forClasspathResource(\"config/init.sql\");\n// after: place file at src/test/resources/config/init.sql, then\nMountableFile.forClasspathResource(\"config/init.sql\"); // or \"/config/init.sql\"","handlingStrategy":"validation","validationCode":"String path = \"config/init.sql\";\nif (getClass().getClassLoader().getResource(path) == null) {\n    throw new IllegalStateException(\"Classpath resource missing before mount: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n    MountableFile f = MountableFile.forClasspathResource(\"config/init.sql\");\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Resource with path\")) {\n        log.error(\"Resource not on classpath: {}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Store mounted files under src/test/resources and reference classpath-relative paths","Assert resource presence in a setup check before starting containers","Match exact casing; classpath lookup is case-sensitive","Use forHostPath for real filesystem files instead"],"tags":["classpath","resource","mount"],"backgroundTag":"resource-not-found","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}