I use maven plugin to set the main class like this :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myapp.main.MainClass</mainClass>
</configuration>
</plugin>
But sometimes I want run my app with another main class. What is the command line arguments to do this?
java -jar myapp-1.0.jar ...
Thx
Spring Boot allows us to define the Main class in the configuration when we have multiple main classes declared in the application. As we are using a MAVEN build, we have to configure the POM. xml for Spring Boot to identify the main class of the application. Voila!
A Spring Boot application's main class is a class that contains a public static void main() method that starts up the Spring ApplicationContext. By default, if the main class isn't explicitly specified, Spring will search for one in the classpath at compile time and fail to start if none or multiple of them are found.
Right click on project -> Properties -> RUN. Make sure the Main Class field is has the correct starter class else Click browse and select from the available classes .
Following command will do the trick:
java -cp my-app.jar -Dloader.main=myApplicationClass org.springframework.boot.loader.PropertiesLauncher
There's a launcher for that in Spring Boot already. You need to build the jar with that as the Main-Class (by setting the layout
in the build config).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With