{"record":{"id":"1f7a4f5c2331ed19","repo":"karatelabs/karate","slug":"cannot-find-resource-path-1f7a4f","errorCode":null,"errorMessage":"cannot find resource: {path}","messagePattern":"cannot find resource: (.+?)","errorType":"exception","errorClass":"ResourceNotFoundException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/common/Resource.java","lineNumber":573,"sourceCode":"                relativePath = relativePath.substring(1);\n            }\n\n            // Try provided classloader, then context classloader, then system classloader\n            URL url = null;\n            if (classLoader != null) {\n                url = classLoader.getResource(relativePath);\n            }\n            if (url == null) {\n                ClassLoader contextCL = Thread.currentThread().getContextClassLoader();\n                if (contextCL != null) {\n                    url = contextCL.getResource(relativePath);\n                }\n            }\n            if (url == null) {\n                url = ClassLoader.getSystemResource(relativePath);\n            }\n            if (url == null) {\n                throw new ResourceNotFoundException(path);\n            }\n            // Convert URL to Path for classpath resources\n            try {\n                Path resourcePath = urlToPath(url, null);\n                return new PathResource(resourcePath, FileUtils.WORKING_DIR.toPath(), true);\n            } catch (java.nio.file.ProviderNotFoundException e) {\n                // JAR file system provider not available (common in jpackage/JavaFX apps)\n                // Fall back to streaming the resource content (root defaults to SYSTEM_TEMP)\n                try (java.io.InputStream is = url.openStream()) {\n                    String content = FileUtils.toString(is);\n                    return new MemoryResource(content);\n                } catch (Exception ex) {\n                    throw new RuntimeException(\"Failed to create resource from classpath: \" + path, ex);\n                }\n            } catch (Exception e) {\n                throw new RuntimeException(\"Failed to create resource from classpath: \" + path, e);\n            }\n        } else if (path.startsWith(FILE_COLON)) {","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/common/Resource.java#L555-L591","documentation":"Resource.path() resolves a classpath-style path by searching the context and system classloaders. When the relative path cannot be found on the classpath (both lookups return null), it throws ResourceNotFoundException with 'cannot find resource: {path}'. This signals the resource is not on the runtime classpath — a lookup failure, not a read failure.","triggerScenarios":"Calling Resource.path('classpath:...') with a path that is not packaged in the jar or under target/classes; typo in the resource path; resource excluded by build filters; running from an IDE/module where the resources directory isn't on the classpath.","commonSituations":"Test fixture under src/test/resources not yet copied to target/test-classes (build not run); resource renamed during a refactor; resource filtered out by Maven resource filtering excludes; classpath differs between IDE and Maven runs.","solutions":["Verify the exact path spelling and that the file lives under src/main/resources or src/test/resources","Rebuild so resources are copied to target/classes / target/test-classes","Use the classpath-relative path without leading slash or 'classpath:' duplication as the API expects","List the jar/target/classes to confirm the resource was packaged"],"exampleFix":"// before\nResource.path(\"classpath:fixtures/missing-data.json\")\n// after (file moved to src/test/resources/fixtures/data.json)\nResource.path(\"classpath:fixtures/data.json\")","handlingStrategy":"validation","validationCode":"// Java: verify resource presence on the classpath before Resource.path\nString rel = \"fixtures/data.json\";\nif (Thread.currentThread().getContextClassLoader().getResource(rel) == null\n        && ClassLoader.getSystemResource(rel) == null) {\n    throw new IllegalStateException(\"not on classpath: \" + rel);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Resource r = Resource.path(\"classpath:fixtures/data.json\");\n} catch (ResourceNotFoundException e) {\n    logger.error(\"classpath resource missing: {}\", e.getMessage());\n    // fail fast with build/packaging guidance\n}","preventionTips":["Keep fixtures under src/test/resources and rebuild before runs","Reference paths exactly as packaged (no leading slash unless required by the API)","Verify packaged contents with jar tf or by listing target/classes","Watch Maven resource filtering excludes that can strip files"],"tags":["classpath","resource-not-found","build"],"backgroundTag":"resource-not-found","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"}