MyCATApache/Mycat-Server · error · IOException
Error opening jar
Error message
Error opening jar: ${fileName} What it means
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.
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
Example fix
// before
loader.loadJar("/apps/udf.jar"); // file missing
// after
File jar = new File("/apps/udf.jar");
if (jar.isFile() && jar.canRead()) loader.loadJar(jar.getAbsolutePath()); Defensive patterns
Strategy: validation
Validate before calling
File jar = new File(fileName);
if (!jar.isFile() || !jar.canRead())
throw new IllegalStateException("Jar missing or unreadable: " + fileName);
try (java.util.jar.JarFile jf = new java.util.jar.JarFile(jar)) { /* valid jar */ } Try / catch
try {
loader.loadJar(fileName);
} catch (IOException e) {
if (e.getMessage().startsWith("Error opening jar")) {
// verify path, integrity (unzip -t), and permissions before retry
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Typos in the jar path in config; partial/failed upload leaving a truncated jar; directory passed instead of file; wrong permissions after deployment.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- Mkdirs failed to create
- can't find myid properties file
- error while calling spill() on
- error while calling spill() on
- Failed to create local dir in $newDir.
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/86732f46441de779.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/classloader/JarLoader.java:58
in.close();
}
}
}
} finally {
jar.close();
}
}
public static Class<?> loadJar(String fileName,String mainJavaclass) throws Exception {
File file = new File(fileName);
String mainClassName = null;
JarFile jarFile;
try {
jarFile = new JarFile(fileName);
} catch(IOException io) {
throw new IOException("Error opening jar: " + fileName);
}
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
mainClassName = manifest.getMainAttributes().getValue("Main-Class");
}
jarFile.close();
if (mainClassName == null) {
mainClassName = mainJavaclass;
}
mainClassName = mainClassName.replaceAll("/", ".");
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
tmpDir.mkdirs();
if (!tmpDir.isDirectory()) {
System.out.println("Mkdirs failed to create " + tmpDir);
}
View on GitHub (pinned to 65f8d8beb7)