Execution default of goal
org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage
failed:
Unable to find a single main class from the following candidates
My project has more than one class with a main
method. How do I tell the Spring Boot Maven plugin which of the classes it should use as the main class?
I had renamed my project and it was still finding the old
Application
class on the build path. I removed it in the 'build' folder and all was fine.If you're using spring-boot-starter-parent in your pom, you simply add the following to your pom:
Then do your mvn package.
See this Spring docs page.
A very important aspect here is to mention that the directory structure has to be src/main/java/nameofyourpackage
For those using Gradle (instead of Maven) :
Since Spring Boot 1.5, you can complete ignore the error-prone string literal in pom or build.gradle. The repackaging tool (via maven or gradle plugin) will pick the one annotated with
@SpringBootApplication
for you. (Refer to this issue for detail: https://github.com/spring-projects/spring-boot/issues/6496 )Add your start class in your pom:
I tried the following code in pom.xml and it worked for me