{"record":{"id":"b67f36c341ce516b","repo":"GoogleContainerTools/jib","slug":"main-class-was-not-found","errorCode":null,"errorMessage":"Main class was not found","messagePattern":"Main class was not found","errorType":"validation","errorClass":"MainClassInferenceException","httpStatus":null,"severity":"error","filePath":"jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java","lineNumber":97,"sourceCode":"              \"'mainClass' configured in \"\n                  + projectProperties.getJarPluginName()\n                  + \" is not a valid Java class: \"\n                  + mainClassFromJarPlugin));\n    }\n    projectProperties.log(\n        LogEvent.info(\n            \"Could not find a valid main class from \"\n                + projectProperties.getJarPluginName()\n                + \"; looking into all class files to infer main class.\"));\n\n    MainClassFinder.Result mainClassFinderResult =\n        MainClassFinder.find(projectProperties.getClassFiles(), projectProperties::log);\n    switch (mainClassFinderResult.getType()) {\n      case MAIN_CLASS_FOUND:\n        return mainClassFinderResult.getFoundMainClass();\n\n      case MAIN_CLASS_NOT_FOUND:\n        throw new MainClassInferenceException(\n            HelpfulSuggestions.forMainClassNotFound(\n                \"Main class was not found\", projectProperties.getPluginName()));\n\n      case MULTIPLE_MAIN_CLASSES:\n        throw new MainClassInferenceException(\n            HelpfulSuggestions.forMainClassNotFound(\n                \"Multiple valid main classes were found: \"\n                    + String.join(\", \", mainClassFinderResult.getFoundMainClasses()),\n                projectProperties.getPluginName()));\n\n      default:\n        throw new IllegalStateException(\"Cannot reach here\");\n    }\n  }\n\n  /**\n   * Checks if a string is a valid Java class name.\n   *","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","solutions":["Explicitly configure the main class (maven: <mainClass>; gradle: mainClass property) instead of relying on inference","Ensure the project's compiled output actually contains a class with a proper main method (check classFiles/compiled classes)","Check the jar plugin configuration for a mainClass typo flagged earlier in the log"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}