본문 바로가기

Spring/Spring-boot

[에러]Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.6.RELEASE:repackage failed: Unable to find a single main class from the following candidates

 

Spring boot프로젝트를 Maven으로 처음 생성한 후 mvn package을 해보았다.

레퍼런스를 보고 따라했는데 에러가 발생하였다.

 

결론은 main이 두 개다.

main() 메서드가 두 개 이기 때문에 maven에서 단일 메인 클래스를 찾을 수 없다는 것 이였다.

 

프로젝트 생성을 spring initializr를 이용해 생성하였고, 레퍼런스를 보고 메인을 하나 더 만들어 버렸다.

initializr가 자동으로 main을 만들어 준다!!!

 

main()메서드를 지우고 나서는 빌드 성공하였다.

 

오류를 찾다보니 jar파일을 만들 때 메인 클래스가 두 개 이상이라도 어떤 클래스를 기본 클래스로 사용해야 하는지 설정 할 수있었다.

 

Maven사용 시 Pom.xml에 시작 클래스 지정.

1
2
3
4
<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>
 

 

Gradle사용 시

1
2
3
springBoot {
    mainClass = "com.example.Main"
}
 

https://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main-class-to-use-for-the-executable-jar