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插件它应该用作哪个类作为主类?
9 回答
10
在你的pom中添加你的起始类:
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>
9 回答
在你的pom中添加你的起始类:
对于那些使用Gradle(而不是Maven)的人:
如果你不使用spring-boot-starter-parent pom,那么从Spring documentation:
如果你在你的pom中使用spring-boot-starter-parent,你只需将以下内容添加到你的pom中:
然后做你的mvn包 .
见this Spring docs page .
这里一个非常重要的方面是提到目录结构必须是src / main / java / nameofyourpackage
对于那些使用Gradle(而不是Maven)的人,引用here:
我在pom.xml中尝试了以下代码,它对我有用
我重命名了我的项目,它仍然在构建路径上找到旧的
Application
类 . 我在'build'文件夹中删除了它,一切都很好 .从Spring Boot 1.5开始,您可以完全忽略pom或build.gradle中容易出错的字符串文字 . 重新打包工具(通过maven或gradle插件)将为您选择带有
@SpringBootApplication
注释的工具 . (有关详细信息,请参阅此问题:https://github.com/spring-projects/spring-boot/issues/6496)在没有明确指定main-class时,已经看到了Java 1.9和SpringBoot 1.5.x的这个问题 .
使用Java 1.8,它能够找到没有显式属性的main-class,并且'mvn package'可以正常工作 .