Thi*_*ilo 168 java spring executable-jar maven spring-boot
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
Run Code Online (Sandbox Code Playgroud)
我的项目有多个带有main
方法的类.我如何告诉Spring Boot Maven插件它应该用作哪个类作为主类?
lud*_*_rj 250
在你的pom中添加你的起始类:
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>
Run Code Online (Sandbox Code Playgroud)
小智 125
对于那些使用Gradle(而不是Maven)的人:
springBoot {
mainClass = "com.example.Main"
}
Run Code Online (Sandbox Code Playgroud)
Ren*_*aud 68
如果你不使用spring-boot-starter-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>
Run Code Online (Sandbox Code Playgroud)
Sha*_* Lu 17
对于那些使用Gradle(而不是Maven)的人,请在此处引用:
也可以使用任务的mainClassName属性显式配置主类:
bootJar {
mainClassName = 'com.example.ExampleApplication'
}
Run Code Online (Sandbox Code Playgroud)
或者,可以使用Spring Boot DSL的mainClassName属性在项目范围内配置主类名:
springBoot {
mainClassName = 'com.example.ExampleApplication'
}
Run Code Online (Sandbox Code Playgroud)
moj*_*ave 12
如果你在你的pom中使用spring-boot-starter-parent,你只需将以下内容添加到你的pom中:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
然后做你的mvn包.
请参阅此Spring文档页面.
这里一个非常重要的方面是提到目录结构必须是src/main/java/nameofyourpackage
小智 6
我在 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>
Run Code Online (Sandbox Code Playgroud)
从 Spring Boot 1.5 开始,你可以完全忽略 pom 或 build.gradle 中容易出错的字符串文字。重新打包工具(通过 maven 或 gradle 插件)会@SpringBootApplication
为你选择一个带注释的。(详细参考本期:https : //github.com/spring-projects/spring-boot/issues/6496)
归档时间: |
|
查看次数: |
156535 次 |
最近记录: |