MyCATApache/Mycat-Server · critical · RuntimeException
can't find class resource file
Error message
can't find class resource file {mapFile} What it means
PartitionByRangeMod.initialize() loads the range-to-node map file from the classpath using ClassLoader.getResourceAsStream(mapFile) and throws this RuntimeException when the stream is null, i.e. the resource is not on the classpath. The failure happens during rule initialization, before any query is routed.
Solutions
- Ensure the range-mod map file exists on the classpath (Mycat conf directory) with exactly the name given in mapFile.
- Fix the mapFile property to a classpath-relative, case-correct resource name (no leading slash or filesystem path).
- Repackage/redeploy so the resource is inside the artifact, then restart Mycat.
- Add a filesystem fallback (FileInputStream(fileMapPath)) in initialize() if loading from disk is required.
Example fix
// before: file on disk only, referenced absolutely <property name="mapFile">/opt/mycat/conf/range-mod.txt</property> // after: file committed to classpath resources <property name="mapFile">range-mod.txt</property>
Defensive patterns
Strategy: validation
Validate before calling
java.io.InputStream s = PartitionByRangeMod.class.getClassLoader().getResourceAsStream(mapFile);
if (s == null) throw new IllegalStateException("mapFile missing from classpath: " + mapFile); else s.close(); Try / catch
try { rule.init(); } catch (RuntimeException e) { if (e.getMessage().contains("can't find class resource file")) { /* place the map file on the classpath */ } throw e; } Prevention
- Commit the range-mod map file to the deployment's conf/resources directory.
- Check mapFile spelling and case against the actual resource name.
- Run rule initialization in an integration test packaged with the same classpath as production.
When it happens
Trigger: init() on a PartitionByRangeMod rule whose <mapFile> (e.g. partition-range-mod.txt) does not resolve to any classpath resource: file absent from conf/, wrong name/case, or an absolute path supplied instead of a resource name.
Common situations: New Mycat install missing the default map file; renaming the map file in schema.xml without renaming the actual file; building a custom distribution that excludes the resources directory; mixing up PartitionByFileMap vs PartitionByRangeMod map file formats and names.
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
- can't find class resource file
- can't find class resource file
- can't find class resource file
- Log already in use? in
- SelfCheck### user all node is empty!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/7c2954b643a62f71.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/function/PartitionByRangeMod.java:162
for(int i =0;i<len;i++){
re[i]=begin+i;
}
return re;
}else{
return null;
}
}
private void initialize() {
BufferedReader in = null;
try {
InputStream fin = this.getClass().getClassLoader()
.getResourceAsStream(mapFile);
if (fin == null) {
throw new RuntimeException("can't find class resource file "
+ mapFile);
}
in = new BufferedReader(new InputStreamReader(fin));
LinkedList<LongRange> longRangeList = new LinkedList<LongRange>();
for (String line = null; (line = in.readLine()) != null;) {
line = line.trim();
if (line.startsWith("#") || line.startsWith("//")) {
continue;
}
int ind = line.indexOf('=');
if (ind < 0) {
System.out.println(" warn: bad line int " + mapFile + " :"
+ line);
continue;
}
String pairs[] = line.substring(0, ind).trim().split("-");
long longStart = NumberParseUtil.parseLong(pairs[0].trim());View on GitHub (pinned to 65f8d8beb7)