{"record":{"id":"6ac86ce95663e611","repo":"GoogleContainerTools/jib","slug":"failed-to-construct-entrypoint-on-javacontainerbui","errorCode":null,"errorMessage":"Failed to construct entrypoint on JavaContainerBuilder; jvmFlags were set, but mainClass is null. Specify the main class using JavaContainerBuilder#setMainClass(String), or consider using MainClassFinder to infer the main class.","messagePattern":"Failed to construct entrypoint on JavaContainerBuilder; jvmFlags were set, but mainClass is null\\. Specify the main class using JavaContainerBuilder#setMainClass\\(String\\), or consider using MainClassFinder to infer the main class\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java","lineNumber":547,"sourceCode":"   * @return this\n   */\n  public JavaContainerBuilder setModificationTimeProvider(\n      ModificationTimeProvider modificationTimeProvider) {\n    this.modificationTimeProvider = modificationTimeProvider;\n    return this;\n  }\n\n  /**\n   * Returns a new {@link JibContainerBuilder} using the parameters specified on the {@link\n   * JavaContainerBuilder}.\n   *\n   * @return a new {@link JibContainerBuilder} using the parameters specified on the {@link\n   *     JavaContainerBuilder}\n   * @throws IOException if building the {@link JibContainerBuilder} fails.\n   */\n  public JibContainerBuilder toContainerBuilder() throws IOException {\n    if (mainClass == null && !jvmFlags.isEmpty()) {\n      throw new IllegalStateException(\n          \"Failed to construct entrypoint on JavaContainerBuilder; \"\n              + \"jvmFlags were set, but mainClass is null. Specify the main class using \"\n              + \"JavaContainerBuilder#setMainClass(String), or consider using MainClassFinder to \"\n              + \"infer the main class.\");\n    }\n    if (classpathOrder.isEmpty()) {\n      throw new IllegalStateException(\n          \"Failed to construct entrypoint because no files were added to the JavaContainerBuilder\");\n    }\n\n    Map<LayerType, FileEntriesLayer.Builder> layerBuilders = new EnumMap<>(LayerType.class);\n\n    // Add classes to layer configuration\n    for (PathPredicatePair directory : addedClasses) {\n      addDirectoryContentsToLayer(\n          layerBuilders,\n          LayerType.CLASSES,\n          directory.path,","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java#L529-L565","documentation":"JavaContainerBuilder.toContainerBuilder requires a mainClass to construct the container entrypoint. If jvmFlags were set but no main class was configured, it throws IllegalStateException — a java invocation with flags but no main class would be broken, so jib refuses to build. This is a configuration-consistency check, not an I/O failure.","triggerScenarios":"Calling setJvmFlags(...) without ever calling setMainClass(...), then toContainerBuilder() (also reachable via createJibContainerBuilder and fromExplodedWar paths).","commonSituations":"Refactored builder code where setMainClass was dropped; relying on MainClassFinder output that was never wired in; building libraries where the main class is discovered only later.","solutions":["Call JavaContainerBuilder#setMainClass(\"com.example.Main\") before toContainerBuilder","Use MainClassFinder to infer the main class from compiled classes and pass it via setMainClass","If jvmFlags aren't needed, either set mainClass anyway or remove the flags so this check doesn't trip","Catch IllegalStateException and prompt for the missing main class in tooling"],"exampleFix":"// before\nbuilder.setJvmFlags(\"-Xms512m\");\nJibContainerBuilder b = builder.toContainerBuilder();\n// after\nbuilder.setJvmFlags(\"-Xms512m\").setMainClass(\"com.example.Main\");\nJibContainerBuilder b = builder.toContainerBuilder();","handlingStrategy":"validation","validationCode":"if (mainClass == null) builder.setMainClass(MainClassFinder.findMainClass(Paths.get(\"target/classes\")).orElse(\"com.example.Main\"));","typeGuard":null,"tryCatchPattern":"try { JibContainerBuilder b = builder.toContainerBuilder(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"mainClass\")) builder.setMainClass(fallbackMainClass); }","preventionTips":["Call setMainClass whenever you call setJvmFlags","Use MainClassFinder to infer the main class for executable apps","Keep jvmFlags and mainClass configuration together in one helper"],"tags":["jib","configuration","entrypoint"],"backgroundTag":"missing-required-argument","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}