{"record":{"id":"cd9d698931b3bdac","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-cd9d69","errorCode":null,"errorMessage":"Could not load classpath init script: {}","messagePattern":"Could not load classpath init script: (.+?)","errorType":"console","errorClass":"ScriptLoadException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java","lineNumber":101,"sourceCode":"    @Override\n    protected void configure() {\n        optionallyMapResourceParameterAsVolume(CONTAINER_CONFIG_LOCATION, configLocation);\n    }\n\n    @Override\n    protected void containerIsStarted(InspectContainerResponse containerInfo) {\n        runInitScriptIfRequired();\n    }\n\n    /**\n     * Load init script content and apply it to the database if initScriptPath is set\n     */\n    private void runInitScriptIfRequired() {\n        if (initScriptPath != null) {\n            try {\n                URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);\n                if (resource == null) {\n                    logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                    throw new ScriptLoadException(\n                        \"Could not load classpath init script: \" + initScriptPath + \". Resource not found.\"\n                    );\n                }\n                String cql = IOUtils.toString(resource, StandardCharsets.UTF_8);\n                DatabaseDelegate databaseDelegate = getDatabaseDelegate();\n                ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, cql);\n            } catch (IOException e) {\n                logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                throw new ScriptLoadException(\"Could not load classpath init script: \" + initScriptPath, e);\n            } catch (ScriptException e) {\n                logger().error(\"Error while executing init script: {}\", initScriptPath, e);\n                throw new ScriptUtils.UncategorizedScriptException(\n                    \"Error while executing init script: \" + initScriptPath,\n                    e\n                );\n            }\n        }","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java#L83-L119","documentation":"In the legacy CassandraContainer (modules/cassandra → org.testcontainers.containers), runInitScriptIfRequired resolves the init script from the context classloader. If getResource returns null, it logs this warning and throws ScriptLoadException indicating the classpath resource was not found. This is a fail-fast for a misconfigured initScriptPath.","triggerScenarios":"withInitScript(path) was called with a path that the context ClassLoader cannot resolve: file missing from target/test-classes, wrong relative path, or path mistakenly including directory prefixes that don't exist on the classpath.","commonSituations":"Script in src/main/resources vs src/test/resources mismatch; filename case-sensitivity issues on Linux CI; resources filtered out by build config; running tests from an IDE with stale output directories.","solutions":["Confirm the file exists under src/test/resources and matches initScriptPath exactly (case included)","Reload/refresh build output (mvn clean test or gradle clean test) so the resource lands in target/test-classes","Check Thread.currentThread().getContextClassLoader().getResource(path) directly in a debug test","Use an absolute-classpath-style path relative to the root, e.g. \"scripts/init.cql\""],"exampleFix":"// before\nwithInitScript(\"InitScript.cql\"); // actual file: initscript.cql on Linux CI\n// after\nwithInitScript(\"init.cql\"); // exact case-matched name under src/test/resources","handlingStrategy":"validation","validationCode":"if (Thread.currentThread().getContextClassLoader().getResource(initScriptPath) == null) {\n    throw new IllegalArgumentException(\"Cassandra init script not found on classpath: \" + initScriptPath);\n}","typeGuard":null,"tryCatchPattern":"try { container.start(); } catch (ScriptLoadException e) { throw new AssertionError(\"Check withInitScript path and case: \" + initScriptPath, e); }","preventionTips":["Match initScriptPath exactly to the resource path including case and package dirs","Clean rebuild so resources land in target/test-classes","Verify resource presence programmatically before container.start()","Avoid mixing src/main/resources and src/test/resources expectations"],"tags":["cassandra","classpath","init-script","resource-not-found"],"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"}