How to run an alternate Java Class in Spring Boot?

time lapse photography of vehicles passing near building

Suppose you want to run a Spring Boot application has some classes with main methods that are not annotated with the @SpringBootApplication annotation. Bdw, hope you are aware that in a Spring Boot Application only one class can have the above-mentioned application.

So how do we run other main classes from a Spring Boot application ?

Here’s the answer, you need to use the below two profiles:-

org.springframework.boot.loader.PropertiesLauncher

this serves as a dispatching entrance class

-Dloader.main

this specifies which class to run

so the complete command would be like:-

java -cp yours.jar -Dloader.main=your.alternative.class.path org.springframework.boot.loader.PropertiesLauncher

1 comment

comments user
Hairstyles

Oh my goodness! an amazing article dude. Thanks Nevertheless I’m experiencing challenge with ur rss . Don抰 know why Unable to subscribe to it. Is there anyone getting identical rss drawback? Anyone who knows kindly respond. Thnkx

Post Comment