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:
- Add or install local jar files to the Maven Project
- Build maven project without version
- Create JWT Token and Sign with RSA Private Key
- Replace element in ArrayList at specific index
- Convert Integer List to int array
- ArrayList removeAll() method not removing elements
- Convert floating point number to fixed point in Python
- What is %matplotlib inline and how to use ?
- Java String substring() example program
- Add python3 kernel to jupyter IPython notebook ?
- Reset jupyter notebook theme to default theme
- Jacoco Maven Plugin Junit Code Coverage Example
- Assign value to static variables from application.properties in Spring Boot ?
- Run a Jupyter Notebook .ipynb file from terminal or cmd prompt
- Websocket connection closed automatically – keepalive Ping example
- Check if a file or folder exists without getting exceptions ?
- Python program to find the greatest of three numbers
- Putty Fatal Error No supported authentication methods available
- Find which users belongs to a specific group in linux
- Check if Python Object is a Number ?
- Remove non-numeric characters from string in Python
- Convert negative to positive number in Python
- Extract numbers from a string in python
- Program to Check Given Number is Odd or Even