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中添加你的起始类:
<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>
其他回答
在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>
如果您正在使用Grade,则可以应用“application”插件而不是“java”插件。这允许在不使用任何Spring Boot Gradle插件任务的情况下指定如下所示的主类。
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'application'
}
application {
mainClassName = 'com.example.ExampleApplication'
}
作为一个很好的好处,你可以使用gradle run运行应用程序,类路径由gradle自动配置。该插件还将应用程序打包为TAR和/或ZIP,包括特定于操作系统的启动脚本。
如果你不使用Spring -boot-start -parent pom,那么从Spring文档:
<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>
对于那些使用Gradle(而不是Maven)的人:
springBoot {
mainClass = "com.example.Main"
}
我已经重命名了我的项目,它仍然在构建路径上找到旧的Application类。我在“构建”文件夹中删除了它,一切正常。