apache/dolphinscheduler · error · RuntimeException
get mainJarName failed:
Error message
get mainJarName failed:
What it means
MainClassExtractor.getMainClassName opens the task's jar as a JarFile and reads the Main-Class attribute from META-INF/MANIFEST.MF. Any failure — unreadable jar, corrupt file, missing manifest, or IO error — is rethrown as a RuntimeException with message 'get mainJarName failed:'.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/MainClassExtractor.java:39
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class MainClassExtractor {
private MainClassExtractor() {
}
public static String getMainClassName(String jarFilePath) {
String mainClassName = null;
try (JarFile jarFile = new JarFile(new File(jarFilePath))) {
Manifest manifest = jarFile.getManifest();
mainClassName = manifest.getMainAttributes().getValue("Main-Class");
} catch (Exception e) {
throw new RuntimeException("get mainJarName failed:", e);
}
return mainClassName;
}
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Verify the file is a valid, executable jar: run 'unzip -p your.jar META-INF/MANIFEST.MF' and confirm a Main-Class entry.
- If Main-Class is missing, rebuild with maven-jar-plugin <mainClass> configured or provide the main class explicitly in the task params.
- Check the jar path exists on the worker (resource downloaded) before extraction.
- Re-upload the jar if it is corrupted.
- Wrap with a null check on getManifest() to produce a clearer error.
Example fix
// before
Manifest manifest = jarFile.getManifest();
mainClassName = manifest.getMainAttributes().getValue("Main-Class");
// after
Manifest manifest = jarFile.getManifest();
if (manifest == null || manifest.getMainAttributes().getValue("Main-Class") == null) {
throw new RuntimeException("jar has no Main-Class manifest attribute: " + jarFilePath);
}
mainClassName = manifest.getMainAttributes().getValue("Main-Class"); Defensive patterns
Strategy: validation
Validate before calling
static void validateExecutableJar(String jarFilePath) throws IOException {
File f = new File(jarFilePath);
if (!f.isFile()) throw new FileNotFoundException(jarFilePath);
try (JarFile jf = new JarFile(f)) {
Manifest m = jf.getManifest();
if (m == null || m.getMainAttributes().getValue("Main-Class") == null) {
throw new IllegalStateException("no Main-Class in " + jarFilePath);
}
}
} Type guard
static boolean hasMainClassAttribute(String jarPath) {
try (JarFile jf = new JarFile(jarPath)) {
Manifest m = jf.getManifest();
return m != null && m.getMainAttributes().getValue("Main-Class") != null;
} catch (Exception e) { return false; }
} Try / catch
try {
String mainClass = MainClassExtractor.getMainClassName(jarPath);
} catch (RuntimeException e) {
log.error("cannot extract Main-Class from {}", jarPath, e.getCause());
// fall back to explicit main class in task params
} Prevention
- Always build runnable jars with the maven-jar-plugin mainClass (or shade plugin) set.
- Use 'jar tf' / 'unzip -p ... META-INF/MANIFEST.MF' to verify before uploading.
- Ensure the resource is fully uploaded and downloaded before the task runs.
- Only select .jar files (not .zip) as main jar in the UI.
When it happens
Trigger: getMainClassName(jarFilePath) is called and new JarFile(...) throws (file missing, not a valid zip/jar, permission denied) or jarFile.getManifest()/getMainAttributes() returns null causing NPE, or reading attributes throws.
Common situations: User selects a non-jar file (e.g. .zip, .class) as the main jar, jar built without Main-Class manifest attribute (no maven-jar-plugin mainClass config), resource not yet downloaded to the worker so the path is empty, or jar is corrupted on upload.
Related errors
- Update Kerberos environment failed.
- Parameter types: " + Lists.newArrayList(standardRpcRequest.g
- DMS task init error
- run java task error
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/a5d96fb30a79f95c.
Report an issue: GitHub.