Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify main class Spring-Boot command line

Tags:

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

like image 702
etig Avatar asked Jun 20 '14 08:06

etig


People also ask

How do you write spring boot main class?

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!

How do you define a class in spring boot?

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.

How do you find the main class in a spring boot project?

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 .


2 Answers

Following command will do the trick:

java -cp my-app.jar -Dloader.main=myApplicationClass org.springframework.boot.loader.PropertiesLauncher
like image 140
Marcus A. Avatar answered Oct 04 '22 14:10

Marcus A.


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

like image 35
Dave Syer Avatar answered Oct 04 '22 13:10

Dave Syer