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.xml中尝试了以下代码,它对我有效
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>myPackage.HelloWorld</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<executable>D:\jdk1.8\bin\javaw.exe</executable>
</configuration>
</plugin>
</plugins>
其他回答
从Spring Boot 1.5开始,你可以完全忽略pom或build.gradle中容易出错的字符串文字。重新打包工具(通过maven或gradle插件)将为你选择带有@SpringBootApplication注释的工具。(详见此问题:https://github.com/spring-projects/spring-boot/issues/6496)
如果你在你的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
我在Java 1.9和SpringBoot 1.5中见过这个问题。X,当main-class未显式指定时。
使用Java 1.8,它能够找到没有显式属性的main-class,并且'mvn package'工作得很好。
在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>
如果你不使用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>