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.
Asked
Active
Viewed 3,180 times
3

Vishnu
- 4,377
- 7
- 26
- 40
2 Answers
6
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

Vishnu
- 4,377
- 7
- 26
- 40
-1
Two answers to your question
- You have to create a MANIFEST.MF file in src/main/resources/META-INF/MANIFEST.MF and give an attribute like this as given below Main-Class= com.yourfilename
- You can use maven jar plugin to define main-class configuration in your manifest file, please use this links below which will help you.
- link 1
link 2

Community
- 1
- 1

Praveen Kumar K S
- 3,024
- 1
- 24
- 31
-
1in the manifest I can specify only one main class. But I would want to be able to specify which class to run on the fly. Something like `mvn exec:java -Dexec.mainClass="com.example.Main"` – Vishnu May 16 '16 at 20:08