{"record":{"id":"86732f46441de779","repo":"MyCATApache/Mycat-Server","slug":"error-opening-jar-filename","errorCode":null,"errorMessage":"Error opening jar: ${fileName}","messagePattern":"Error opening jar: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/classloader/JarLoader.java","lineNumber":58,"sourceCode":"\t            in.close();\r\n\t          }\r\n\t        }\r\n\t      }\r\n\t    } finally {\r\n\t      jar.close();\r\n\t    }\r\n\t  }\r\n\t  \r\n\t  public static Class<?> loadJar(String fileName,String mainJavaclass) throws Exception {\r\n\r\n\t\t    File file = new File(fileName);\r\n\t\t    String mainClassName = null;\r\n\r\n\t\t    JarFile jarFile;\r\n\t\t    try {\r\n\t\t      jarFile = new JarFile(fileName);\r\n\t\t    } catch(IOException io) {\r\n\t\t      throw new IOException(\"Error opening jar: \" + fileName);\r\n\t\t    }\r\n\r\n\t\t    Manifest manifest = jarFile.getManifest();\r\n\t\t    if (manifest != null) {\r\n\t\t      mainClassName = manifest.getMainAttributes().getValue(\"Main-Class\");\r\n\t\t    }\r\n\t\t    jarFile.close();\r\n\r\n\t\t    if (mainClassName == null) {\r\n\t\t      mainClassName = mainJavaclass;\r\n\t\t    }\r\n\t\t    mainClassName = mainClassName.replaceAll(\"/\", \".\");\r\n\r\n\t\t    File tmpDir = new File(System.getProperty(\"java.io.tmpdir\"));\r\n\t\t    tmpDir.mkdirs();\r\n\t\t    if (!tmpDir.isDirectory()) { \r\n\t\t    \tSystem.out.println(\"Mkdirs failed to create \" + tmpDir);\r\n\t\t    }\r","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/classloader/JarLoader.java#L40-L76","documentation":"JarLoader.loadJar opens the jar with new JarFile(fileName); any IOException while opening (missing file, not a zip/jar, corrupted, permission denied) is rethrown as IOException('Error opening jar: <fileName>'). The original cause is discarded, so the message is the only clue.","triggerScenarios":"Calling loadJar with a path that does not exist, points to a non-jar/corrupted file, or a file the process cannot read; jar locked or truncated during download.","commonSituations":"Typos in the jar path in config; partial/failed upload leaving a truncated jar; directory passed instead of file; wrong permissions after deployment.","solutions":["Verify the jar path exists and is a valid, complete jar (unzip -t <file>)","Fix read permissions so the Mycat process user can open the file","Re-upload/re-download the jar if it is truncated or corrupt","Check you passed the jar file path, not a directory"],"exampleFix":"// before\nloader.loadJar(\"/apps/udf.jar\"); // file missing\n// after\nFile jar = new File(\"/apps/udf.jar\");\nif (jar.isFile() && jar.canRead()) loader.loadJar(jar.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File jar = new File(fileName);\nif (!jar.isFile() || !jar.canRead())\n    throw new IllegalStateException(\"Jar missing or unreadable: \" + fileName);\ntry (java.util.jar.JarFile jf = new java.util.jar.JarFile(jar)) { /* valid jar */ }","typeGuard":null,"tryCatchPattern":"try {\n    loader.loadJar(fileName);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Error opening jar\")) {\n        // verify path, integrity (unzip -t), and permissions before retry\n    }\n}","preventionTips":["Verify jar existence/readability right after deployment","Validate jar integrity after transfer (checksum or unzip -t)","Never point loadJar at a directory or a partially downloaded file"],"tags":["io","jar","file-not-found"],"backgroundTag":"file-open-failed","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"}