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.
Error: Could not find or load main class com.example.App
Caused by: java.lang.ClassNotFoundException: com.example.AppCommon 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.
java -cp build/classes/java/main com.example.App
# for a jar, ensure the manifest has Main-Class:
java -jar app.jarFix packaging so the main class ships
Configure the jar/shade plugin to set Main-Class and include compiled output.
<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-Classand include compiled classes.