{"record":{"id":"7b7f510ee636f504","repo":"karatelabs/karate","slug":"boot-classpath-dir-expected-a-directory-relative-to-the","errorCode":null,"errorMessage":"boot.classpath('${dir}'): expected a directory RELATIVE to the project root (e.g. 'src/test/resources'), not an absolute or prefixed reference","messagePattern":"boot\\.classpath\\('(.+?)'\\): expected a directory RELATIVE to the project root \\(e\\.g\\. 'src/test/resources'\\), not an absolute or prefixed reference","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/BootBinding.java","lineNumber":156,"sourceCode":"     * re-anchors to. One committed line makes a Maven/Gradle project resolve its references\n     * identically under a JVM run — where the classloader hits and this mapping stays inert — and\n     * under a bare-folder serve run, where the fallback carries {@code classpath:} refs to the\n     * declared dir.\n     *\n     * <p>The argument is a <b>root-relative reference</b>, so {@code file:} / {@code classpath:} /\n     * {@code this:} and Windows drive-letter absolutes are rejected. {@code ''} is valid and means\n     * the root itself (the \"unify only, map nothing\" spelling) — which is also what an undeclared\n     * project gets, so a bare-folder project never needs this call. Last call wins.</p>\n     */\n    public void classpath(String dir) {\n        if (dir == null) {\n            throw new IllegalArgumentException(\"boot.classpath: dir is null — pass a project-relative \"\n                    + \"directory such as 'src/test/resources', or '' for the project root\");\n        }\n        if (dir.startsWith(Resource.FILE_COLON) || dir.startsWith(Resource.CLASSPATH_COLON)\n                || dir.startsWith(Resource.THIS_COLON)\n                || (!dir.startsWith(\"/\") && java.nio.file.Path.of(dir).isAbsolute())) {\n            throw new IllegalArgumentException(\"boot.classpath('\" + dir + \"'): expected a directory \"\n                    + \"RELATIVE to the project root (e.g. 'src/test/resources'), not an absolute or \"\n                    + \"prefixed reference\");\n        }\n        this.classpathDir = Resource.stripLeadingSlashes(dir);\n    }\n\n    /**\n     * The directory declared by {@link #classpath(String)}, root-relative and de-slashed, or\n     * {@code null} when the project declared nothing (then the fallback dir IS the root).\n     */\n    public String getClasspathDir() {\n        return classpathDir;\n    }\n\n    /**\n     * {@code boot.read('path')} — read a text file, on the one unified rule: a leading {@code /}\n     * anchors THE project root, a bare ref is root-relative, {@code classpath:} is\n     * classloader-first then the {@link #classpath(String)} fallback, and {@code file:} is a host","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/BootBinding.java#L138-L174","documentation":"boot.classpath(dir) only accepts a directory path relative to the project root. Paths with file:, classpath:, or this: prefixes, or absolute paths (leading '/' or a Windows drive letter), are rejected with an IllegalArgumentException because the boot classpath mapping is by definition project-root-relative.","triggerScenarios":"Calling boot.classpath('file:/abs/path'), boot.classpath('classpath:foo'), boot.classpath('this:dir'), boot.classpath('/etc/somewhere'), or boot.classpath('C:\\\\tools\\\\res') — any prefixed or absolute reference.","commonSituations":"Reusing a classpath-style resource string in the boot config; hard-coding an absolute machine path that breaks portability; converting an old file: based read into a boot.classpath call without stripping the prefix.","solutions":["Strip the prefix and make the path relative to the project root, e.g. boot.classpath('src/test/resources').","Use '' if the intended directory is the project root itself.","For host-absolute locations, move/link the resources inside the project instead of pointing boot.classpath outside it."],"exampleFix":"// before\nboot.classpath('file:/home/me/proj/src/test/resources');\n// after\nboot.classpath('src/test/resources');","handlingStrategy":"validation","validationCode":"// before calling boot.classpath(dir)\nassert dir != null && !dir.startsWith(\"file:\") && !dir.startsWith(\"classpath:\")\n    && !dir.startsWith(\"this:\") && !dir.startsWith(\"/\")\n    && !java.nio.file.Path.of(dir).isAbsolute()\n    : \"boot.classpath expects a project-relative directory\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write boot.classpath arguments as relative paths like 'src/test/resources'.","Never copy classpath:/file: resource strings into boot.classpath.","Keep resources inside the project instead of referencing absolute host paths."],"tags":["boot","configuration","path-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}