karatelabs/karate · error · ResourceNotFoundException
cannot find resource
Error message
cannot find resource: ${path} What it means
HtmlTemplateResolver resolves template paths to Resources and throws ResourceNotFoundException (message 'cannot find resource: <path>') when the resolved resource is null or does not exist. This happens while loading a top-level template or while resolving an included/called fragment relative to the owner template.
Solutions
- Verify the path in the error exists relative to the configured template root (check spelling and case)
- Confirm the resource is on the classpath / copied into target output for jar deployments
- Fix the resolver/root configuration (WorkingDir, resource root) to match where templates live
- Check the calling fragment's relative path — includes resolve against the owner template's location
Example fix
// before
kaThymeleaf.render("pages/dashborad.html", model); // typo
// after
kaThymeleaf.render("pages/dashboard.html", model); Defensive patterns
Strategy: try-catch
Validate before calling
Resource r = resolver.resolve(path, caller); if (r == null || !r.exists()) throw new IllegalStateException("template missing: " + path); Try / catch
try { render(path, model); } catch (ResourceNotFoundException e) { log.error("template not found: {}", e.getMessage()); throw e; } Prevention
- Verify template paths relative to the configured root (mind case sensitivity)
- Ensure templates are copied into build output / packaged in the jar
- Resolve includes relative to the calling template's directory
- Add a startup smoke test that renders key templates
When it happens
Trigger: Rendering a template whose file path does not resolve under the configured root; an include/insert referencing a fragment file that is missing or misnamed; wrong working directory or classpath root so the resource cannot be located.
Common situations: Typo in template or fragment path; template file not copied into the build output/jar; configured template root points at the wrong directory; case-sensitive filesystems vs wrong-cased paths in CI/Linux.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- cannot find resource
- boot.read: file not found
- boot.ext(' '): does not implement io.karatelabs.core.Ext
- boot.ext(' '): not on classpath. Expected (name-convention…
- Failed to open stream for:
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/cd7b2efb4b5157df.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/markup/HtmlTemplateResolver.java:89
prevCaller = null;
HtmlStringTemplateResource templateResource = new HtmlStringTemplateResource(content, resolver);
return new TemplateResolution(templateResource, TemplateMode.HTML, NonCacheableCacheEntryValidity.INSTANCE);
} else { // html file name
if (!content.endsWith(".html")) {
content = content + ".html";
}
Resource caller;
// Only resolve ownerTemplate as caller if it's a valid template name (not HTML content or markers)
if (ownerTemplate != null && !ownerTemplate.startsWith(Resource.THIS_COLON) && prevCaller != null) {
// ownerTemplate needs .html extension too
String ownerPath = ownerTemplate.endsWith(".html") ? ownerTemplate : ownerTemplate + ".html";
caller = resolver.resolve(ownerPath, null);
} else {
caller = prevCaller;
}
Resource resource = resolver.resolve(content, caller);
if (resource == null || !resource.exists()) {
throw new ResourceNotFoundException(content);
}
prevCaller = resource;
HtmlTemplateResource templateResource = new HtmlTemplateResource(ownerTemplate, resource);
return new TemplateResolution(templateResource, TemplateMode.HTML,
devMode ? NonCacheableCacheEntryValidity.INSTANCE : AlwaysValidCacheEntryValidity.INSTANCE);
}
}
}
View on GitHub (pinned to a22eb90246)