{"record":{"id":"59deaed2c15809b4","repo":"apache/flink","slug":"the-given-program-class-does-not-have-a-main-strin","errorCode":null,"errorMessage":"The given program class does not have a main(String[]) method.","messagePattern":"The given program class does not have a main\\(String\\[\\]\\) method\\.","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":166,"sourceCode":"        this.userCodeClassLoader =\n                ClientUtils.buildUserCodeClassLoader(\n                        getJobJarAndDependencies(),\n                        classpaths,\n                        getClass().getClassLoader(),\n                        configuration);\n\n        // load the entry point class\n        this.mainClass =\n                loadMainClass(\n                        // if no entryPointClassName name was given, we try and look one up through\n                        // the manifest\n                        entryPointClassName != null\n                                ? entryPointClassName\n                                : getEntryPointClassNameFromJar(this.jarFile),\n                        userCodeClassLoader);\n\n        if (!hasMainMethod(mainClass)) {\n            throw new ProgramInvocationException(\n                    \"The given program class does not have a main(String[]) method.\");\n        }\n\n        this.descriptor =\n                new PackagedProgramDescriptor(\n                        jarFile,\n                        classpaths,\n                        configuration,\n                        savepointRestoreSettings,\n                        args,\n                        getMainClassName());\n    }\n\n    public PackagedProgramDescriptor getDescriptor() {\n        return descriptor;\n    }\n\n    public SavepointRestoreSettings getSavepointSettings() {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L148-L184","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","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[])."],"exampleFix":"// before\npublic class MyJob {\n    public void run(String[] args) { ... }\n}\n\n// after\npublic class MyJob {\n    public static void main(String[] args) throws Exception { ... }\n}","handlingStrategy":"validation","validationCode":"private static boolean hasValidMain(Class<?> c) {\n    try {\n        Method m = c.getMethod(\"main\", String[].class);\n        int mod = m.getModifiers();\n        return Modifier.isPublic(mod) && Modifier.isStatic(mod)\n            && Modifier.isPublic(c.getModifiers());\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}\n// Call before constructing PackagedProgram:\nif (!hasValidMain(MyJob.class)) {\n    throw new IllegalArgumentException(\"MyJob lacks a public static main(String[])\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    PackagedProgram pp = PackagedProgram.newBuilder().setJarFile(jar).build();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().contains(\"does not have a main\")) {\n        // guide user to provide --class or fix the jar manifest\n    } else { throw pie; }\n}","preventionTips":["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."],"tags":["packaged-program","main-method","jar","entry-point"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}