{"record":{"id":"7dbe6eae67fd1104","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-initscriptpath-resource-7dbe6e","errorCode":null,"errorMessage":"Could not load classpath init script: ${initScriptPath}. Resource not found.","messagePattern":"Could not load classpath init script: (.+?)\\. Resource not found\\.","errorType":"exception","errorClass":"org.testcontainers.ext.ScriptUtils.ScriptLoadException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java","lineNumber":102,"sourceCode":"    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        }\n    }","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java#L84-L120","documentation":"CassandraContainer.runInitScriptIfRequired loads the configured init script (via withInitScript) from the thread context classpath. If getResource returns null, the resource does not exist on the classpath and a ScriptLoadException is thrown. The message includes the configured initScriptPath.","triggerScenarios":"container.withInitScript(\"init.cql\").start() where init.cql is not present on the test classpath (resource lookup via context classloader returns null).","commonSituations":"Init script placed in project root instead of src/test/resources; wrong leading path (classpath lookup never resolves absolute filesystem paths); file excluded from the jar/test resources by build config.","solutions":["Place the script under src/test/resources (e.g. src/test/resources/init.cql) and rebuild","Reference it with the correct classpath-relative path, e.g. withInitScript(\"cassandra/init.cql\") for src/test/resources/cassandra/init.cql","Verify the resource exists in the build output (target/test-classes) and is not filtered/excluded in Maven/Gradle config"],"exampleFix":"// before\nnew CassandraContainer(\"cassandra:4.0\").withInitScript(\"/home/me/init.cql\");\n// after (file moved to src/test/resources/db/init.cql)\nnew CassandraContainer(\"cassandra:4.0\").withInitScript(\"db/init.cql\");","handlingStrategy":"validation","validationCode":"URL r = Thread.currentThread().getContextClassLoader().getResource(\"db/init.cql\");\nif (r == null) throw new IllegalStateException(\"init script missing from test classpath\");","typeGuard":null,"tryCatchPattern":"try { container.start(); } catch (ContainerLaunchException e) { /* check classpath resource presence */ }","preventionTips":["Always put init scripts in src/test/resources","Reference scripts by classpath-relative path, never absolute filesystem paths","Verify the resource appears in target/test-classes after build"],"tags":["cassandra","testcontainers","classpath","resource-not-found","init-script"],"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"}