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
我的项目有一个主方法的多个类。我如何告诉Spring Boot Maven插件它应该使用哪个类作为主类?
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
我的项目有一个主方法的多个类。我如何告诉Spring Boot Maven插件它应该使用哪个类作为主类?
当前回答
如果你在你的pom中使用spring-boot-starter-parent,你只需添加以下内容到你的pom:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
然后做你的mvn包。
请看这个Spring文档页面。
这里很重要的一点是,目录结构必须是src/main/java/nameofyourpackage
其他回答
Kotlin with Gradle:
springBoot {
mainClass.set("com.example.MainKt")
}
如果你在你的pom中使用spring-boot-starter-parent,你只需添加以下内容到你的pom:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
然后做你的mvn包。
请看这个Spring文档页面。
这里很重要的一点是,目录结构必须是src/main/java/nameofyourpackage
我已经重命名了我的项目,它仍然在构建路径上找到旧的Application类。我在“构建”文件夹中删除了它,一切正常。
我在Java 1.9和SpringBoot 1.5中见过这个问题。X,当main-class未显式指定时。
使用Java 1.8,它能够找到没有显式属性的main-class,并且'mvn package'工作得很好。
对于那些使用Gradle(而不是Maven)的人:
springBoot {
mainClass = "com.example.Main"
}