小编典典

如何告诉Spring Boot可执行jar使用哪个主类?

spring

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

我的项目有多个使用main方法的类。如何告诉Spring Boot Maven插件应将其用作主类?


阅读 469

收藏
2020-04-12

共2个答案

小编典典

Add your start class in your pom:

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

or

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>             
        <configuration>    
            <mainClass>com.mycorp.starter.HelloWorldApplication</mainClass>
        </configuration>
    </plugin>
</plugins>
</build>
2020-04-12
小编典典

对于使用Gradle(而不是Maven)的用户:

springBoot {
    mainClass = "com.example.Main"
}
2020-04-12