{"record":{"id":"9eeb2a3fc5f49576","repo":"GoogleContainerTools/jib","slug":"main-class-attribute-for-an-application-main-cl-9eeb2a","errorCode":null,"errorMessage":"`Main-Class:` attribute for an application main class not defined in the input JAR's manifest (`META-INF/MANIFEST.MF` in the JAR).","messagePattern":"`Main-Class:` attribute for an application main class not defined in the input JAR's manifest \\(`META-INF/MANIFEST\\.MF` in the JAR\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/StandardPackagedProcessor.java","lineNumber":67,"sourceCode":"\n    // Add layer for jar.\n    FileEntriesLayer jarLayer =\n        FileEntriesLayer.builder()\n            .setName(JarLayers.JAR)\n            .addEntry(jarPath, JarLayers.APP_ROOT.resolve(jarPath.getFileName()))\n            .build();\n    layers.add(jarLayer);\n\n    return layers;\n  }\n\n  @Override\n  public ImmutableList<String> computeEntrypoint(List<String> jvmFlags) throws IOException {\n    try (JarFile jarFile = new JarFile(jarPath.toFile())) {\n      String mainClass =\n          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);\n      if (mainClass == null) {\n        throw new IllegalArgumentException(\n            \"`Main-Class:` attribute for an application main class not defined in the input JAR's \"\n                + \"manifest (`META-INF/MANIFEST.MF` in the JAR).\");\n      }\n      ImmutableList.Builder<String> entrypoint = ImmutableList.builder();\n      entrypoint.add(\"java\");\n      entrypoint.addAll(jvmFlags);\n      entrypoint.add(\"-jar\");\n      entrypoint.add(JarLayers.APP_ROOT + \"/\" + jarPath.getFileName().toString());\n      return entrypoint.build();\n    }\n  }\n\n  @Override\n  public Integer getJavaVersion() {\n    return jarJavaVersion;\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/StandardPackagedProcessor.java#L49-L85","documentation":"When using a packaged (non-exploded) standard JAR as the build input, Jib reads `Main-Class` from META-INF/MANIFEST.MF to compose the `java -jar` entrypoint. A missing attribute triggers this IllegalArgumentException in StandardPackagedProcessor.computeEntrypoint.","triggerScenarios":"Calling computeEntrypoint on a packaged standard JAR whose manifest lacks the `Main-Class:` attribute (getValue(Attributes.Name.MAIN_CLASS) returns null).","commonSituations":"Containerizing a library JAR without a main class; forgetting the jar-plugin manifest configuration; fat JAR repackaging that drops the Main-Class attribute; mismatched processor selection treating the JAR as a standard app.","solutions":["Add `Main-Class` to the JAR manifest in the build tool and repackage the JAR","Provide an explicit entrypoint/args via Containerizer or Jib CLI flags instead of manifest-based inference","Verify the JAR actually has a main class (`unzip -p app.jar META-INF/MANIFEST.MF`) before containerizing"],"exampleFix":"// pom.xml (before)\n<plugin>maven-jar-plugin, no archive config</plugin>\n// after\n<archive><manifest><mainClass>com.example.Main</mainClass></manifest></archive>","handlingStrategy":"validation","validationCode":"try (JarFile jf = new JarFile(jarPath.toFile())) {\n  if (jf.getManifest() == null || jf.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS) == null) throw new IllegalStateException(\"JAR has no Main-Class\");\n}","typeGuard":null,"tryCatchPattern":"try { entrypoint = processor.computeEntrypoint(jvmFlags); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Main-Class\")) { entrypoint = userProvidedEntrypoint; } }","preventionTips":["Set mainClass in maven-jar-plugin or Gradle jar manifest config","Check manifest content after any shading/repackaging step","Provide explicit entrypoints when manifest inference is undesirable"],"tags":["jib","jar","manifest","main-class","entrypoint"],"backgroundTag":"missing-required-config-field","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}