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

新手上路,请多包涵
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 插件它应该使用哪个类作为主类?

原文由 Thilo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 646
2 个回答

在你的 pom 中添加你的开始类:

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

或者

<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>

原文由 ludo_rj 发布,翻译遵循 CC BY-SA 4.0 许可协议

对于那些使用 Gradle(而不是 Maven)的人:

 springBoot {
    mainClass = "com.example.Main"
}

原文由 Marcelo C. 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题