How do I tell Spring Boot which main class to use for the executable jar? How do I tell Spring Boot which main class to use for the executable jar? java java

How do I tell Spring Boot which main class to use for the executable jar?


Add your start class in your 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>


For those using Gradle (instead of Maven) :

springBoot {    mainClass = "com.example.Main"}


If you do NOT use the spring-boot-starter-parent pom, then from the Spring documentation:

<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>