apache/flink · error · ProgramInvocationException
The given program class does not have a main(String[]) metho
Error message
The given program class does not have a main(String[]) method.
What it means
Thrown by the PackagedProgram constructor after successfully loading the entry point class, when hasMainMethod returns false — i.e. the class has no method matching public static void main(String[]). The class resolved and loaded, but it is not a valid entry point for 'flink run'.
Source
Thrown at flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java:166
this.userCodeClassLoader =
ClientUtils.buildUserCodeClassLoader(
getJobJarAndDependencies(),
classpaths,
getClass().getClassLoader(),
configuration);
// load the entry point class
this.mainClass =
loadMainClass(
// if no entryPointClassName name was given, we try and look one up through
// the manifest
entryPointClassName != null
? entryPointClassName
: getEntryPointClassNameFromJar(this.jarFile),
userCodeClassLoader);
if (!hasMainMethod(mainClass)) {
throw new ProgramInvocationException(
"The given program class does not have a main(String[]) method.");
}
this.descriptor =
new PackagedProgramDescriptor(
jarFile,
classpaths,
configuration,
savepointRestoreSettings,
args,
getMainClassName());
}
public PackagedProgramDescriptor getDescriptor() {
return descriptor;
}
public SavepointRestoreSettings getSavepointSettings() {View on GitHub (pinned to 2f3c205e92)
Solutions
- Confirm the entry point class defines 'public static void main(String[] args)'.
- If using --class, pass the fully-qualified name of the class that actually contains main(String[]).
- If relying on the jar manifest, set 'Main-Class' (standard) or Flink's 'program-class' attribute to the correct driver class and rebuild the jar.
- Verify the class is public top-level (or public static nested) and the method signature is exactly String[] (not String... or Object[]).
Example fix
// before
public class MyJob {
public void run(String[] args) { ... }
}
// after
public class MyJob {
public static void main(String[] args) throws Exception { ... }
} Defensive patterns
Strategy: validation
Validate before calling
private static boolean hasValidMain(Class<?> c) {
try {
Method m = c.getMethod("main", String[].class);
int mod = m.getModifiers();
return Modifier.isPublic(mod) && Modifier.isStatic(mod)
&& Modifier.isPublic(c.getModifiers());
} catch (NoSuchMethodException e) {
return false;
}
}
// Call before constructing PackagedProgram:
if (!hasValidMain(MyJob.class)) {
throw new IllegalArgumentException("MyJob lacks a public static main(String[])");
} Try / catch
try {
PackagedProgram pp = PackagedProgram.newBuilder().setJarFile(jar).build();
} catch (ProgramInvocationException pie) {
if (pie.getMessage().contains("does not have a main")) {
// guide user to provide --class or fix the jar manifest
} else { throw pie; }
} Prevention
- Always define 'public static void main(String[] args)' in the entry class.
- Set the manifest 'Main-Class' (or Flink 'program-class') during the build so the jar is self-describing.
- Use the maven-shade-plugin ManifestResourceTransformer to set mainClass automatically.
When it happens
Trigger: Constructing a PackagedProgram with an entryPointClassName (or a jar whose manifest points to a class) that lacks a conforming main(String[]) method. Also triggered when the main method exists but is not both public and static (hasMainMethod checks both).
Common situations: Pointing flink at a library JAR or an inner class instead of the real driver class. Providing a class that implements Flink interfaces (e.g. a ProcessFunction) but has no main. Manifest 'program-class'/'Main-Class' pointing to a utility class.
Related errors
- No manifest found in jar file '{jarFile.getPath()}'. The man
- Neither a '{MANIFEST_ATTRIBUTE_MAIN_CLASS}', nor a '{MANIFES
- Could not look up the main(String[]) method from the class %
- The class %s must be public.
- The class %s has no main(String[]) method.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/59deaed2c15809b4.
Report an issue: GitHub.