Skip to content
Latchkey

Java "Could not find or load main class" in CI - Fix Classpath

The JVM could not locate the main class you asked it to run. The name is wrong, the class is not on the classpath, or the jar lacks the compiled class or a Main-Class entry.

What this error means

Running the app fails with Error: Could not find or load main class com.example.App. Compilation may have succeeded; the launch cannot find the entry point.

java runtime
Error: Could not find or load main class com.example.App
Caused by: java.lang.ClassNotFoundException: com.example.App

Common causes

Wrong main-class name or path

A typo, a wrong package, or passing a file path instead of the fully-qualified class name means the JVM cannot resolve the class.

Class not on the classpath / not in the jar

The -cp is wrong, or the packaged jar did not include the compiled classes or a Main-Class manifest entry, so the entry point is absent at runtime.

How to fix it

Run with the correct classpath and FQN

Point -cp at the compiled output and pass the fully-qualified class name.

Terminal
java -cp build/classes/java/main com.example.App
# for a jar, ensure the manifest has Main-Class:
java -jar app.jar

Fix packaging so the main class ships

Configure the jar/shade plugin to set Main-Class and include compiled output.

pom.xml (jar/shade plugin)
<manifest>
  <mainClass>com.example.App</mainClass>
</manifest>

How to prevent it

  • Pass fully-qualified class names, verify the runtime classpath, and configure packaging to set Main-Class and include compiled classes.

Frequently asked questions

What causes ""Could not find or load main class""?
A typo, a wrong package, or passing a file path instead of the fully-qualified class name means the JVM cannot resolve the class.
How do I fix "Could not find or load main class"?
Point -cp at the compiled output and pass the fully-qualified class name.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card