apache/dubbo · error · FileNotFoundException
{description} cannot be resolved to URL because it does not
Error message
{description} cannot be resolved to URL because it does not exist What it means
IOUtils.getURL resolves a 'classpath:' prefixed resource location and, when the ClassLoader cannot find the resource on the classpath, throws FileNotFoundException with a descriptive class-path-resource message. The resource must exist at the exact path within the deployed JAR/classes directory.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java:262
}
writeLines(new FileOutputStream(file, true), lines);
}
/**
* use like spring code
*
* @param resourceLocation
* @return
*/
public static URL getURL(String resourceLocation) throws FileNotFoundException {
Assert.notNull(resourceLocation, "Resource location must not be null");
if (resourceLocation.startsWith(CommonConstants.CLASSPATH_URL_PREFIX)) {
String path = resourceLocation.substring(CommonConstants.CLASSPATH_URL_PREFIX.length());
ClassLoader cl = ClassUtils.getClassLoader();
URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
if (url == null) {
String description = "class path resource [" + path + "]";
throw new FileNotFoundException(description + " cannot be resolved to URL because it does not exist");
}
return url;
}
try {
// try URL
return new URL(resourceLocation);
} catch (MalformedURLException ex) {
// no URL -> treat as file path
try {
return new File(resourceLocation).toURI().toURL();
} catch (MalformedURLException ex2) {
throw new FileNotFoundException(
"Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path");
}
}
}
public static byte[] toByteArray(final InputStream inputStream) throws IOException {View on GitHub (pinned to 3a3043227f)
Solutions
- Confirm the resource exists under target/classes or inside the JAR at the expected path
- Use forward slashes and no leading slash in the classpath path argument
- Ensure the resource is under src/main/resources and not excluded by maven `<resources>` configuration
- If loading from another module, add it as a dependency so it lands on the classpath
Example fix
// before
URL u = IOUtils.getURL("classpath:/config/app.yaml");
// after
URL u = IOUtils.getURL("classpath:config/app.yaml"); Defensive patterns
Strategy: validation
Validate before calling
String path = "config/app.yaml";
ClassLoader cl = MyClass.class.getClassLoader();
if (cl.getResource(path) == null) { /* missing on classpath; fix build before calling getURL */ } Type guard
static boolean classpathResourceExists(String p) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return (cl != null ? cl : ClassLoader.getSystemClassLoader()).getResource(p) != null;
} Try / catch
try { URL u = IOUtils.getURL("classpath:" + path); }
catch (java.io.FileNotFoundException e) { /* resource not packaged; check build */ } Prevention
- Use forward slashes and no leading slash in classpath paths
- Verify resources appear under target/classes in CI
When it happens
Trigger: Calling IOUtils.getURL("classpath:" + path) where path does not match any packaged resource; common with trailing slashes, wrong package separators, or resources excluded from the build artifact.
Common situations: Resource files not copied into target/classes by the build (missing src/main/resources placement or resources filtering); typo in the path; resource only present in a module not on the runtime classpath; fat-jar shading that relocated the file.
Related errors
- Resource location [{resourceLocation}] is neither a URL not
- Invalid configurator rule, please specify at least one param
- service field in configuration is null.
- Illegal affinity rule!
- Illegal route rule!
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/e538f808205dc835.
Report an issue: GitHub.