Specify the main class Spring -Boot command line

I use the maven plugin to set the main class as follows:

<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 to run my application with a different main class. What are these command line arguments?

 java -jar myapp-1.0.jar ... 

thanks

+7
java spring spring-boot
source share
3 answers

There is a launch for Spring Boot already . You need to build a jar with the main class (by setting layout in the assembly configuration ).

+5
source share

The following command will do the trick:

 java -cp my-app.jar -Dloader.main=myApplicationClass org.springframework.boot.loader.PropertiesLauncher 
+15
source share

Running with Windows PowerShell I need this format (with quotes):

java -cp .\myjarfile.jar -D"loader.main=com.app.etc.FullyQualifiedMainClass" org.springframework.boot.loader.PropertiesLauncher

To clarify the accepted answer: you can directly change the loader.main property in the META-INF / MANIFEST.MF file in the bank if you are ok with a more static solution.

+1
source share

All Articles