{"record":{"id":"7c2954b643a62f71","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-class-resource-file-mapfile-7c2954","errorCode":null,"errorMessage":"can't find class resource file {mapFile}","messagePattern":"can't find class resource file (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/route/function/PartitionByRangeMod.java","lineNumber":162,"sourceCode":"            for(int i =0;i<len;i++){\n                re[i]=begin+i;\n            }\n\n            return re;\n        }else{\n            return null;\n        }\n\t}\n\n\n\n\tprivate void initialize() {\n\t\tBufferedReader in = null;\n\t\ttry {\n\t\t\tInputStream fin = this.getClass().getClassLoader()\n\t\t\t\t\t.getResourceAsStream(mapFile);\n\t\t\tif (fin == null) {\n\t\t\t\tthrow new RuntimeException(\"can't find class resource file \"\n\t\t\t\t\t\t+ mapFile);\n\t\t\t}\n\t\t\tin = new BufferedReader(new InputStreamReader(fin));\n\t\t\tLinkedList<LongRange> longRangeList = new LinkedList<LongRange>();\n\n\t\t\tfor (String line = null; (line = in.readLine()) != null;) {\n\t\t\t\tline = line.trim();\n\t\t\t\tif (line.startsWith(\"#\") || line.startsWith(\"//\")) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint ind = line.indexOf('=');\n\t\t\t\tif (ind < 0) {\n\t\t\t\t\tSystem.out.println(\" warn: bad line int \" + mapFile + \" :\"\n\t\t\t\t\t\t\t+ line);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t\tString pairs[] = line.substring(0, ind).trim().split(\"-\");\n\t\t\t\t\tlong longStart = NumberParseUtil.parseLong(pairs[0].trim());","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/function/PartitionByRangeMod.java#L144-L180","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: file on disk only, referenced absolutely\n<property name=\"mapFile\">/opt/mycat/conf/range-mod.txt</property>\n// after: file committed to classpath resources\n<property name=\"mapFile\">range-mod.txt</property>","handlingStrategy":"validation","validationCode":"java.io.InputStream s = PartitionByRangeMod.class.getClassLoader().getResourceAsStream(mapFile);\nif (s == null) throw new IllegalStateException(\"mapFile missing from classpath: \" + mapFile); else s.close();","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["classpath","resource-not-found","sharding-config","startup"],"backgroundTag":"resource-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}