GoogleContainerTools/jib · error · MainClassInferenceException

Main class was not found

Error message

Main class was not found

What it means

MainClassInferenceException thrown by MainClassResolver.resolveMainClass() when automatic inference fails completely: no mainClass was configured, the jar plugin provided none, and MainClassFinder.find() scanned all compiled class files (MAIN_CLASS_NOT_FOUND) without discovering any class containing a valid 'public static void main' method. The build cannot determine the container entrypoint, so it aborts with a helpful-suggestion message.

Source

Thrown at jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java:97

              "'mainClass' configured in "
                  + projectProperties.getJarPluginName()
                  + " is not a valid Java class: "
                  + mainClassFromJarPlugin));
    }
    projectProperties.log(
        LogEvent.info(
            "Could not find a valid main class from "
                + projectProperties.getJarPluginName()
                + "; looking into all class files to infer main class."));

    MainClassFinder.Result mainClassFinderResult =
        MainClassFinder.find(projectProperties.getClassFiles(), projectProperties::log);
    switch (mainClassFinderResult.getType()) {
      case MAIN_CLASS_FOUND:
        return mainClassFinderResult.getFoundMainClass();

      case MAIN_CLASS_NOT_FOUND:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Main class was not found", projectProperties.getPluginName()));

      case MULTIPLE_MAIN_CLASSES:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Multiple valid main classes were found: "
                    + String.join(", ", mainClassFinderResult.getFoundMainClasses()),
                projectProperties.getPluginName()));

      default:
        throw new IllegalStateException("Cannot reach here");
    }
  }

  /**
   * Checks if a string is a valid Java class name.
   *

View on GitHub (pinned to fb949e2676)

Solutions

  1. Explicitly configure the main class (maven: <mainClass>; gradle: mainClass property) instead of relying on inference
  2. Ensure the project's compiled output actually contains a class with a proper main method (check classFiles/compiled classes)
  3. Check the jar plugin configuration for a mainClass typo flagged earlier in the log
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java:97 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/b67f36c341ce516b. Report an issue: GitHub.