{"record":{"id":"9c68218545beca46","repo":"GoogleContainerTools/jib","slug":"main-class-attribute-for-an-application-main-cl","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/StandardExplodedProcessor.java","lineNumber":98,"sourceCode":"            isResourceFile,\n            JarLayers.APP_ROOT.resolve(\"explodedJar\"));\n\n    if (!resourcesLayer.getEntries().isEmpty()) {\n      layers.add(resourcesLayer);\n    }\n    if (!classesLayer.getEntries().isEmpty()) {\n      layers.add(classesLayer);\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      String classpath =\n          JarLayers.APP_ROOT + \"/explodedJar:\" + JarLayers.APP_ROOT + \"/dependencies/*\";\n      ImmutableList.Builder<String> entrypoint = ImmutableList.builder();\n      entrypoint.add(\"java\");\n      entrypoint.addAll(jvmFlags);\n      entrypoint.add(\"-cp\");\n      entrypoint.add(classpath);\n      entrypoint.add(mainClass);\n      return entrypoint.build();\n    }\n  }\n\n  @Override\n  public Integer getJavaVersion() {\n    return jarJavaVersion;","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/StandardExplodedProcessor.java#L80-L116","documentation":"When exploding a standard (non-Spring-Boot) JAR, Jib derives the container entrypoint from the `Main-Class` attribute in META-INF/MANIFEST.MF. If the attribute is absent, StandardExplodedProcessor.computeEntrypoint throws this IllegalArgumentException because it cannot construct a `java -cp ... main.Class` entrypoint.","triggerScenarios":"Calling computeEntrypoint on an exploded standard JAR whose manifest has no `Main-Class:` main attribute (getMainAttributes().getValue(MAIN_CLASS) returns null).","commonSituations":"Packaging a library JAR (no main class) and trying to containerize it as an app; building with plain `jar`/Gradle/Maven without setting Main-Class; manifest overwritten by shading or repackaging plugins.","solutions":["Set Main-Class in the JAR manifest (e.g. Maven jar plugin `<archive><manifest><mainClass>` or Gradle `jar { manifest { attributes 'Main-Class': ... } }`) and rebuild","Use `jib.from`/entrypoint overrides or pass an explicit entrypoint instead of relying on manifest inference","If containerizing a library, add a wrapper main class or use a base image with a defined entrypoint"],"exampleFix":"// build.gradle (before)\njar { }\n// after\njar {\n  manifest { attributes 'Main-Class': 'com.example.Main' }\n}","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":["Configure Main-Class in your build tool manifest settings","Verify `unzip -p app.jar META-INF/MANIFEST.MF` shows Main-Class before containerizing","Don't containerize library JARs as applications"],"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"}