This error usually happens when the Spring Boot jar is not repackaged correctly by Maven. Even though the project compiles, the jar may not be executable unless the Spring Boot Maven plugin repackages it.
Here are the steps to fix it:
---
### 1. Add the Spring Boot Maven plugin (MOST IMPORTANT)
Make sure your `pom.xml` contains this plugin:
<plugin>
\<groupId\>org.springframework.boot\</groupId\>
\<artifactId\>spring-boot-maven-plugin\</artifactId\>
\<version\>${spring-boot.version}\</version\>
\<executions\>
\<execution\>
\<goals\>
\<goal\>repackage\</goal\>
\</goals\>
\</execution\>
\</executions\>
</plugin>
This ensures Maven creates an executable jar with the correct BOOT-INF structure.
---
### 2. Clean and rebuild the project
Run:
mvn clean package
After this, verify that the jar contains your main class:
jar tf target/myapp-0.0.1-SNAPSHOT.jar | grep Application
You should see it under BOOT-INF/classes.
---
### 3. Check main class configuration (if custom)
If you specified a custom main class, ensure it:
- Exists in BOOT-INF/classes
- Uses `@SpringBootApplication`
- Matches the package structure
---
### 4. Run the jar
java -jar target/myapp-0.0.1-SNAPSHOT.jar
Now the application should run without the ClassNotFoundException.
---
### ✔ Summary
The issue happens because the Spring Boot plugin never repackaged the jar. Adding the plugin and rebuilding fixes this error in almost all Spring Boot Maven builds.