Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple SpringBootApplication classes from a single maven project

Is there a way to specify which SpringBootApplication's main class to run when running mvn spring-boot:run? The docs say I can use mainClass parameter to specify which main class to run. But I am not sure how to specify it in command line. I have tried mvn -DmainClass=mypackage.myclass spring-boot:run but it didn't work.

like image 722
Vishnu Avatar asked Dec 05 '25 13:12

Vishnu


1 Answers

I got it working by having a placeholder in the plugin configuration of spring-boot

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${mainclass}</mainClass>
            </configuration>
        </plugin>

and then running different classes

mvn -Dmainclass=mypackage.myclass spring-boot:run
like image 83
Vishnu Avatar answered Dec 09 '25 14:12

Vishnu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!