Search code examples
springspring-bootlaunchermainclass

Is there any "SpringBoot way" so i can start different Main Classes Applications from the same Jar File?


I Mean, that i DON´T want to create a Centralizer Main Class and pass parameter to it, so it can choose and start the @SpringBoot class for me...

In the other hand, I do not consider starting the classes with "java -cp ". This way it is not SpringBoot which starts the classes, but you are forcing manually the class to be started.

What i am looking for is an elegant built-in "Spring Way" to start my diferent @SpringBoot classes from command line. Any Special Launcher? Something in the App properties files?

What i realize is a Launcher which may receive "spring.application.name" for instance by command line and so use that to choose the desired @SpringBoot class.


Solution

  • You can not put multiple Main Classes in the Manifest.

    What you can do is put the JAR in the classpath and call the main class

    java -jar yourLib.jar will start the Main Class from manifest

    java -cp youLib.jar your.1st.main.Class

    java -cp youLib.jar your.2nd.main.Class