{"record":{"id":"d18297eb3de54e76","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-cassandracontainer","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/cassandra/CassandraContainer.java","lineNumber":104,"sourceCode":"    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 (this.initScriptPath != null) {\n            try {\n                final MountableFile originalInitScript = MountableFile.forClasspathResource(this.initScriptPath);\n                // The init script is executed as is by the cqlsh command, so copy it into the container. The name\n                // of the script is generic since it's not important to keep the original name.\n                copyFileToContainer(originalInitScript, DEFAULT_INIT_SCRIPT_FILENAME);\n                new CassandraDatabaseDelegate(this).execute(null, DEFAULT_INIT_SCRIPT_FILENAME, -1, false, false);\n            } catch (IllegalArgumentException e) {\n                // MountableFile.forClasspathResource will throw an IllegalArgumentException if the resource cannot\n                // be found.\n                logger().warn(\"Could not load classpath init script: {}\", this.initScriptPath);\n                throw new ScriptLoadException(\n                    \"Could not load classpath init script: \" + this.initScriptPath + \". Resource not found.\",\n                    e\n                );\n            } catch (ScriptUtils.ScriptStatementFailedException e) {\n                logger().error(\"Error while executing init script: {}\", this.initScriptPath, e);\n                throw new ScriptUtils.UncategorizedScriptException(\n                    \"Error while executing init script: \" + this.initScriptPath,\n                    e\n                );\n            }\n        }\n    }\n\n    /**\n     * Initialize Cassandra with the custom overridden Cassandra configuration\n     * <p>\n     * Be aware, that Docker effectively replaces all /etc/cassandra content with the content of config location, so if","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/cassandra/CassandraContainer.java#L86-L122","documentation":"In the newer CassandraContainer (modules/cassandra), runInitScriptIfRequired copies the classpath init script into the container and executes it. When the classpath resource cannot be resolved (MountableFile/IllegalArgumentException), it logs this warning and throws ScriptLoadException. The configured init script simply was not found on the classpath.","triggerScenarios":"Calling .withInitScript(\"init.cql\") where the resource cannot be loaded from the classpath: wrong path, file outside the classpath root, missing leading consideration (paths are relative to classpath root), or resource packaged in a dependency that isn't on the runtime classpath.","commonSituations":"Typo in the script path; script lives in src/test/resources but the path includes src/test/resources prefix; file placed under a package directory but referenced without the package path; Maven/Gradle not copying resources.","solutions":["Place the CQL script under src/test/resources and reference it relative to the classpath root, e.g. withInitScript(\"cql/init.cql\") for src/test/resources/cql/init.cql","Verify the resource exists at runtime: getClass().getClassLoader().getResourceAsStream(\"cql/init.cql\") != null","Rebuild so resources are copied (mvn test vs mvn package inconsistencies; Gradle processResources)","Catch ScriptLoadException in test setup and print the resolved classpath for debugging"],"exampleFix":"// before\nnew CassandraContainer<>(\"cassandra:4.0\").withInitScript(\"src/test/resources/init.cql\");\n// after\nnew CassandraContainer<>(\"cassandra:4.0\").withInitScript(\"init.cql\"); // file at src/test/resources/init.cql","handlingStrategy":"validation","validationCode":"static void assertClasspathResource(String path) {\n    if (Thread.currentThread().getContextClassLoader().getResource(path) == null) {\n        throw new IllegalStateException(\"Init script not on classpath: \" + path);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (ScriptLoadException e) {\n    throw new IllegalStateException(\"Fix withInitScript path (relative to classpath root): \" + e.getMessage(), e);\n}","preventionTips":["Reference init scripts relative to the classpath root, never with src/test/resources prefixes","Keep script filenames case-exact (CI Linux is case-sensitive)","Add the script under src/test/resources and verify it appears in target/test-classes after build","Smoke-test resource lookup with getClass().getClassLoader().getResource() in a unit test"],"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"}