0

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?

New contributor
Basudev Haldar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 1
    add some code, the pom.xml for example and the project structure. Commented yesterday
  • The BOOT-INF/classes directory being there but the rest not and the application not being executable seem to indicate that your build process started but was stuck in a middle state, probably due to a wrong configuration (missing or wrong execution config of plugin e.g.). For proper help you need to add at least your complete pom.xml Commented yesterday
  • Please do not manually set the main class in Spring Boot's pom.xml. Commented 6 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.