{"record":{"id":"171f9dcf006b80c4","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-orientdbcontainer","errorCode":null,"errorMessage":"Could not load classpath init script: {}","messagePattern":"Could not load classpath init script: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/orientdb/src/main/java/org/testcontainers/containers/OrientDBContainer.java","lineNumber":177,"sourceCode":"            }\n        } else {\n            orientDB.createIfNotExists(databaseName, ODatabaseType.PLOCAL);\n        }\n        if (session == null) {\n            session = orientDB.open(databaseName, username, password);\n\n            scriptPath.ifPresent(path -> loadScript(path, session));\n        }\n        return session;\n    }\n\n    @Deprecated\n    private void loadScript(String path, ODatabaseSession session) {\n        try {\n            URL resource = getClass().getClassLoader().getResource(path);\n\n            if (resource == null) {\n                LOGGER.warn(\"Could not load classpath init script: {}\", scriptPath);\n                throw new RuntimeException(\n                    \"Could not load classpath init script: \" + scriptPath + \". Resource not found.\"\n                );\n            }\n\n            String script = IOUtils.toString(resource, StandardCharsets.UTF_8);\n\n            session.execute(\"sql\", script);\n        } catch (IOException e) {\n            LOGGER.warn(\"Could not load classpath init script: {}\", scriptPath);\n            throw new RuntimeException(\"Could not load classpath init script: \" + scriptPath, e);\n        } catch (UnsupportedOperationException e) {\n            LOGGER.error(\"Error while executing init script: {}\", scriptPath, e);\n            throw new RuntimeException(\"Error while executing init script: \" + scriptPath, e);\n        }\n    }\n}\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/orientdb/src/main/java/org/testcontainers/containers/OrientDBContainer.java#L159-L195","documentation":"OrientDBContainer.loadScript logs this warning when the classpath resource for the init script cannot be found, then throws a RuntimeException. Init scripts are loaded from the application classpath via ClassLoader.getResource; a null resource means the path is wrong or the file is not on the classpath. getSession() calls loadScript when withInitScript was configured, so container startup fails.","triggerScenarios":"Calling withInitScript(\"scripts/init.sql\") where no such resource exists on the classpath (missing from src/test/resources, wrong path, or absent file extension).","commonSituations":"Script placed in src/main instead of test resources; path given with leading '/' or wrong case on Linux CI; resource excluded by build filters or not copied by Gradle/Maven.","solutions":["Verify the script exists under src/test/resources and the path matches exactly (case-sensitive).","Check the built jar/classes directory to confirm the resource is copied to the classpath.","Wrap getSession in try-catch for RuntimeException if the script is optional, or remove the withInitScript call."],"exampleFix":"// before\ncontainer.withInitScript(\"init/orient-init.sql\"); // file missing on classpath\n// after\ncontainer.withInitScript(\"scripts/orient-init.sql\"); // file at src/test/resources/scripts/orient-init.sql","handlingStrategy":"validation","validationCode":"String path = \"scripts/orient-init.sql\";\nif (getClass().getClassLoader().getResource(path) == null) {\n    throw new IllegalStateException(\"Init script not on classpath: \" + path);\n}\ncontainer.withInitScript(path);","typeGuard":"boolean classpathResourceExists(String path) {\n    return getClass().getClassLoader().getResource(path) != null;\n}","tryCatchPattern":"try {\n    Object session = container.getSession();\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Could not load classpath init script\")) {\n        logger.warn(\"Init script missing; continuing without it\", e);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Place init scripts in src/test/resources and use exact case-sensitive paths","Verify resources are copied into target/test-classes or the built jar","Avoid leading slashes and platform-specific path separators"],"tags":["orientdb","classpath","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"}