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

  1. Verify the file is a valid, executable jar: run 'unzip -p your.jar META-INF/MANIFEST.MF' and confirm a Main-Class entry.
  2. If Main-Class is missing, rebuild with maven-jar-plugin <mainClass> configured or provide the main class explicitly in the task params.
  3. Check the jar path exists on the worker (resource downloaded) before extraction.
  4. Re-upload the jar if it is corrupted.
  5. 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

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


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/a5d96fb30a79f95c. Report an issue: GitHub.