quarkusio/quarkus · error · RuntimeException
Unable to find a valid main method on class '${originalMainC
Error message
Unable to find a valid main method on class '${originalMainClassName}'. See https://openjdk.org/jeps/445 for details of what constitutes a valid main method. What it means
After locating the configured main class, Quarkus transforms its bytecode to generate a standard static main entry point. doApply validates that the class contains a valid main-method candidate per JEP 445 rules (public static void main(String[]), or supported instance forms); if none is valid, this RuntimeException is thrown pointing at the JEP 445 definition.
Source
Thrown at core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java:590
*/
private static class MainMethodTransformer implements BiFunction<String, ClassVisitor, ClassVisitor> {
private final IndexView index;
public MainMethodTransformer(IndexView index) {
this.index = index;
}
@Override
public ClassVisitor apply(String mainClassName, ClassVisitor outputClassVisitor) {
ClassInfo mainClassInfo = index.getClassByName(mainClassName);
if (mainClassInfo == null) {
throw new IllegalStateException(mainClassName + " should have a corresponding ClassInfo at this point");
}
ClassTransformer transformer = new ClassTransformer(mainClassName);
Result result = doApply(mainClassName, outputClassVisitor, transformer, mainClassInfo);
if (!result.isValid) {
throw new RuntimeException(errorMessage(mainClassName));
}
if (result.classVisitor == null) {
throw new IllegalStateException("result.classvisitor should not be null at this point");
}
return result.classVisitor;
}
private Result doApply(String originalMainClassName,
ClassVisitor classVisitor, ClassTransformer transformer,
ClassInfo currentClassInfo) {
boolean isTopLevel = currentClassInfo.name().toString().equals(originalMainClassName);
boolean allowStatic = isTopLevel;
boolean hasStaticWithArgs = false;
boolean hasStaticWithoutArgs = false;
boolean hasInstanceWithArgs = false;
boolean hasInstanceWithoutArgs = false;
MethodInfo withArgs = currentClassInfo.method("main", STRING_ARRAY);View on GitHub (pinned to e1c734241f)
Solutions
- Declare the main method as public static void main(String[] args) in the configured class
- Fix the signature casing/modifiers of the existing main method
- Add the missing String[] parameter or remove unsupported extra parameters
- Check the quarkus.main-class value points at the class that actually contains the main method
Example fix
// before
public class Main {
void main() { System.out.println("hi"); }
}
// after
public class Main {
public static void main(String[] args) { System.out.println("hi"); }
} Defensive patterns
Strategy: validation
Validate before calling
Class<?> c = Main.class;
for (Method m : c.getDeclaredMethods()) {
if (m.getName().equals("main")
&& java.lang.reflect.Modifier.isPublic(m.getModifiers())
&& java.lang.reflect.Modifier.isStatic(m.getModifiers())
&& Arrays.equals(m.getParameterTypes(), new Class<?>[]{String[].class})) {
return; // valid
}
}
throw new IllegalStateException("No valid public static void main(String[]) on " + c.getName()); Try / catch
try {
quarkusBuild();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("Unable to find a valid main method")) {
// fix the main method signature per JEP 445
}
throw e;
} Prevention
- Standard signature: public static void main(String[] args)
- Check modifiers/parameter types when the compiler or IDE warns about entry points
- Point quarkus.main-class at the class that actually declares main
- Prefer @QuarkusMain classes implementing QuarkusApplication to avoid signature pitfalls
When it happens
Trigger: In the ClassVisitor's apply(): Result.isValid is false after scanning the main class and its hierarchy — no method matching a valid main signature exists on the class configured as quarkus.main-class or auto-detected main class.
Common situations: Main method declared with the wrong signature (non-static, non-public, missing String[] parameter, wrong casing 'Main'); main method with an incompatible parameter type; class only has a 'void main()' instance method under a Java version whose support doesn't match; abstract class without an inherited concrete main.
Related errors
- Failed to open path tree with root %s
- Dev services for ${request.getName()} requires a startable s
- Name cannot start with '/':${name}
- The class (${name}) cannot be created during deployment.
- Use GeneratedServiceProviderBuildItem to register service pr
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/03336ba5a8459cc3.
Report an issue: GitHub.