Spring Boot App Program Error: Could not find or load main class

Spring Boot App Program Error: Could not find or load main class

This tutorial guides you on how to resolve Spring Boot App Program Error: Could not find or load main class. Occasionally, we might see error “Could not find or load main class” while running Spring Boot App or any Java Program. Let’s see how to resolve the same.

Spring Boot App Program Error: Could not find or load main class

Well, I have created a Spring Boot Application with necessary changes for my App to run. Note, I have created this Spring Boot project using Spring Boot wizard from Eclipse. After, making necessary changes I tried to run the Spring Boot App using the following option:

Right Click Spring Boot Project in Eclipse -> Run As -> Spring Boot App

But it failed with error “Could not find or load main class”.

Error: Could not find or load main class com.de.sneppets.connectivity.ExampleSpringBootApplication
Caused by: java.lang.ClassNotFoundException: com.de.sneppets.connectivity.ExampleSpringBootApplication

And this is the case you might come across even for other Java Program or Projects.

Fix 1: mvn clean install

First, try building the Spring Boot App and check if that resolves the above issue.

What I did was. I tried to build the Spring Boot App from the command line again.

> mvn clean install

And the Build was successful. After building the code successfully, I tried to run the Spring Boot App again. And I don’t see that error any more. Check if this works for you.

Fix 2: Update Project

This is another way which you could try to resolve main class load error. All that you need to do is Update Maven Project using the following option.

Right Click Spring Boot Project -> Maven -> Update Project

And in the Update Maven Project wizard select the Maven Project that you wanted to update with default update options and click “OK”.

After, you do the above step try running your Spring Boot App. Yay! it worked for me. And I don’t see the error any more.

That’s it. The main reason for the error “Could not find or load main class” is due to compiled classes not found in the target directory. Therefore, we need to follow any one of the above approach to build the code to generate classes, so that your Spring Boot App will run successfully.

Hope this is helpful 🙂

You’ll also like:

References:

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments