{"record":{"id":"6f13bca6f26dc13d","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-class-resource-file-mapfile-6f13bc","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/PartitionByFileMap.java","lineNumber":116,"sourceCode":"\t\t\tthrow new IllegalArgumentException(new StringBuilder().append(\"columnValue:\").append(columnValue).append(\" Please check if the format satisfied.\").toString(),e);\r\n\t\t}\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic int getPartitionNum() {\r\n\t\tSet<Integer> set = new HashSet<Integer>(app2Partition.values());\r\n\t\tint count = set.size();\r\n\t\treturn count;\r\n\t}\r\n\r\n\tprivate void initialize() {\r\n\t\tBufferedReader in = null;\r\n\t\ttry {\r\n\t\t\t// FileInputStream fin = new FileInputStream(new File(fileMapPath));\r\n\t\t\tInputStream fin = this.getClass().getClassLoader()\r\n\t\t\t\t\t.getResourceAsStream(mapFile);\r\n\t\t\tif (fin == null) {\r\n\t\t\t\tthrow new RuntimeException(\"can't find class resource file \"\r\n\t\t\t\t\t\t+ mapFile);\r\n\t\t\t}\r\n\t\t\tin = new BufferedReader(new InputStreamReader(fin));\r\n\t\t\t\r\n\t\t\tapp2Partition = new HashMap<Object, Integer>();\r\n\t\t\t\r\n\t\t\tfor (String line = null; (line = in.readLine()) != null;) {\r\n\t\t\t\tline = line.trim();\r\n\t\t\t\tif (line.startsWith(\"#\") || line.startsWith(\"//\")) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tint ind = line.indexOf('=');\r\n\t\t\t\tif (ind < 0) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\ttry {\r\n\t\t\t\t\tString key = line.substring(0, ind).trim();\r\n\t\t\t\t\tint pid = Integer.parseInt(line.substring(ind + 1).trim());\r","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/function/PartitionByFileMap.java#L98-L134","documentation":"PartitionByFileMap.initialize() loads its key->partition mapping from a classpath resource named by the mapFile property. When getResourceAsStream returns null (resource not on the classpath), it throws this RuntimeException. The shard function cannot be initialized without its mapping file.","triggerScenarios":"Calling init() with a mapFile that does not exist, a relative path not under the classpath, a wrong filename/case, or the file not being packaged/deployed to the Mycat conf classpath directory.","commonSituations":"Deploying rule.xml to a new server without copying the map file; typo in mapFile name; file placed in filesystem path instead of classpath; packaging (war/jar) excludes the resource.","solutions":["Place the map file in the Mycat classpath (conf directory) and ensure mapFile matches its exact name.","Verify with the same classloader path: the file must be resolvable via getResourceAsStream, not an absolute filesystem path.","Check filename case and extension; Linux classpath lookup is case-sensitive."],"exampleFix":"// before\n<property name=\"mapFile\">partition-map.txt</property> <!-- file missing from conf/ -->\n// after\ncp partition-map.txt /opt/mycat/conf/\n<property name=\"mapFile\">partition-map.txt</property>","handlingStrategy":"validation","validationCode":"boolean found = PartitionByFileMap.class.getClassLoader().getResource(mapFile) != null;\nif (!found) throw new IllegalStateException(\"mapFile not on classpath: \" + mapFile);\n","typeGuard":null,"tryCatchPattern":"try {\n    function.init();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"can't find class resource file\")) {\n        // fail deployment fast with pointer to missing conf file\n    }\n}","preventionTips":["Ship map files in the same deployment artifact as rule.xml","Verify resource presence in a startup health check","Use exact, case-consistent filenames across environments"],"tags":["classpath","resource-not-found","configuration"],"backgroundTag":"file-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"}