I built a Spring Boot application using Maven, and the project compiles without any errors. However, when I run the packaged jar using : java -jar target/myapp-0.0.1-SNAPSHOT.jar I get the following error:
Exception in thread "main" java.lang.ClassNotFoundException: com.example.Application
The class `com.example.Application` exists in my project, and it is the main class annotated with `@SpringBootApplication`. The application runs fine inside the IDE, but the executable jar fails to start.
I checked the jar structure using:
jar tf target/myapp-0.0.1-SNAPSHOT.jar and noticed that the BOOT-INF/classes directory is present, but the application still fails with the same error.
What is the correct way to fix this issue and ensure that the jar is packaged with all dependencies and the correct entry point?