首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何告诉Spring Boot将哪个主类用于可执行jar?

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

Stack Overflow用户
提问于 2014-04-22 18:31:21
回答 9查看 195.6K关注 0票数 200
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插件它应该使用哪些类作为主类?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2014-04-22 18:41:22

在pom中添加start类:

<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>
票数 288
EN

Stack Overflow用户

发布于 2015-06-25 11:19:16

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

springBoot {
    mainClass = "com.example.Main"
}
票数 134
EN

Stack Overflow用户

发布于 2014-07-07 16:22:48

如果您不使用spring-boot-starter-parent pom,那么从Spring documentation

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.1.3.RELEASE</version>
    <configuration>
        <mainClass>my.package.MyStartClass</mainClass>
        <layout>ZIP</layout>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
票数 71
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23217002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档