{"record":{"id":"29d7c44f8bf65efe","repo":"junit-team/junit5","slug":"could-not-find-any-resource-s-with-name-this-c","errorCode":null,"errorMessage":"Could not find any resource(s) with name: ${this.classpathResourceName}","messagePattern":"Could not find any resource\\(s\\) with name: (.+?)","errorType":"validation","errorClass":"PreconditionViolationException","httpStatus":null,"severity":"error","filePath":"junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java","lineNumber":132,"sourceCode":"\t/**\n\t * Get the selected {@link Resource resources}.\n\t *\n\t * <p>If the {@link Resource resources} were not provided, but only their name,\n\t * this method attempts to lazily load the {@link Resource resources} based on\n\t * their name and throws a {@link PreconditionViolationException} if the\n\t * resource cannot be loaded.\n\t *\n\t * @since 1.14\n\t */\n\t@API(status = MAINTAINED, since = \"1.14\")\n\tpublic Set<Resource> getResources() {\n\t\tif (this.resources == null) {\n\t\t\tTry<Set<Resource>> tryToGetResource = ResourceSupport.tryToGetResources(this.classpathResourceName);\n\t\t\tSet<Resource> classpathResources = tryToGetResource.getNonNullOrThrow( //\n\t\t\t\tcause -> new PreconditionViolationException( //\n\t\t\t\t\t\"Could not load resource(s) with name: \" + this.classpathResourceName, cause));\n\t\t\tif (classpathResources.isEmpty()) {\n\t\t\t\tthrow new PreconditionViolationException(\n\t\t\t\t\t\"Could not find any resource(s) with name: \" + this.classpathResourceName);\n\t\t\t}\n\t\t\tthis.resources = unmodifiableSet(classpathResources);\n\t\t}\n\t\treturn this.resources;\n\t}\n\n\t/**\n\t * Get the selected {@code FilePosition} within the classpath resource.\n\t */\n\tpublic Optional<FilePosition> getPosition() {\n\t\treturn Optional.ofNullable(this.position);\n\t}\n\n\t/**\n\t * @since 1.3\n\t */\n\t@API(status = STABLE, since = \"1.3\")","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java#L114-L150","documentation":"ClasspathResourceSelector.getResources() first tries to load Resource(s) for the configured name (failure yields 'Could not load', a different message), then, if the resulting set is empty, throws PreconditionViolationException 'Could not find any resource(s)'. So this specific message means the lookup succeeded but matched zero resources on the classpath.","triggerScenarios":"Selecting a classpath resource by name (selectClasspathResource) where nothing matches: a typo, wrong path separator, the resource is on a classpath root that is not actually present, or the name refers to a package/directory rather than a resource file.","commonSituations":"Discovery using --select-resource with a misspelled name; the resource lives in a test source dir not copied to the classpath; a Gradle/Maven setup that filters resources and the name does not match post-filtering; slash vs dot confusion.","solutions":["Confirm the resource name exactly matches a path on the classpath (use '/' separators, no leading slash): 'META-INF/foo.json'.","Ensure the containing jar/directory is actually on the classpath/module path passed to the launcher.","If the resource is generated, build the project first so it lands on the classpath before discovery runs.","Distinguish this 'not found' (empty result) from 'could not load' (I/O error) — fix the name first, then the classpath."],"exampleFix":"// before\nLauncherDiscoveryRequest r = request().select(selectClasspathResource(\"meta-inf/foo.json\")).build();\n// after — exact path with correct case and separators\nLauncherDiscoveryRequest r = request().select(selectClasspathResource(\"META-INF/foo.json\")).build();","handlingStrategy":"validation","validationCode":"// Confirm the resource exists on the classpath before discovery.\nString name = \"META-INF/foo.json\"; // '/'-separated, no leading slash, exact case\nClassLoader cl = Thread.currentThread().getContextClassLoader();\nif (cl == null || Collections.list(cl.getResources(name)).isEmpty())\n  throw new IllegalArgumentException(\"No classpath resource named '\" + name + \"' visible to the launcher classloader\");\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exact case and '/' separators for resource names.","Ensure the containing jar/dir is actually on the classpath/module path passed to the launcher.","Build/generate resources before running discovery so they are present on the classpath."],"tags":["discovery","classpath","resource-selector","engine"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}