Spring Boot - How to specify an alternate start-class? (Multiple Entry Points)

The Gilbert Arenas Dagger :

I want to add an alternate entry point to my Spring-Boot application. I would prefer to keep this as a fat jar. Is this possible?

According to their documentation, the property loader.main specifies the name of the main class to launch.

I tried java -jar MyJar.jar --loader.main=com.mycompany.AlternateMain but the start-class specified in my pom.xml was still run (and if I remove this from the pom.xml then I error during the packaging).

Alternatively, I tried java -cp MyJar.jar com.mycompany.AlternateMain but I don't know of a good way to add all the nested jars to the classpath.

Any suggestions?

Edit: Here is the solution that I used

As jst suggested, I changed my launcher to use the PropertiesLauncher. I did this by modifying the configuration of my spring-boot-maven-plugin.

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <mainClass>${start-class}</mainClass>
    <layout>ZIP</layout>
    ...

The <layout>ZIP</layout> triggers Spring Boot to use the PropertiesLauncher.

I created my fat jar (mvn package) then called the alternate main like this:

java -jar -Dloader.main=com.mycompany.AlternateMain MyJar.jar

Thanks for the help!

jst :

I don't believe that property would apply in your case. There are 3 different "Launchers" (go back to the docs and see). If you are building a jar it uses the JarLauncher class. If you switch it to PropertiesLauncher then loader.main would be useful.

META-INF/MANIFEST.MF

Main-Class: org.springframework.boot.loader.PropertiesLauncher

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to see specify class list in spring-boot?

Liquibase with Spring Boot and multiple schemas, how to specify execution order

Spring Boot: How to specify the PasswordEncoder?

How to start a new Thread in spring boot app from the same class

How to start a new Thread in spring boot app from the same class

How to have multiple spring boot batch Configuration class

How to create multiple instances of a scheduler class in spring boot?

How to specify prefix for all controllers in Spring Boot?

How do I specify a BeanNamingStrategy with Spring Boot?

How to specify the Launcher in Spring Boot Gradle?

How to specify a fallback request mapping in Spring Boot

How to specify logging.config when multiple Spring Boot Apps are deployed on tomcat

Configuring Spring Security 3.x to have multiple entry points

npm multiple entry points

Multiple entry points in GWTP

Multiple entry points in Vite

How to alternate animate polyline points?

Class Object creation with python, How to specify a specific type as entry?

Specify main class Spring-Boot command line

Multiple configuration tree to one class in spring boot

Using service class in Spring Boot for multiple repositories

How can I have multiple entry points in a package.json?

How to start the web application with Spring Boot and Kotlin

Ordering multiple entry points in Webpack

How to alternate ng-class?

Spring boot - How to Specify Java path in Process Builder

How to specify a profile when deploying a Spring boot war file to Tomcat?

How to specify external properties files in application.properties in Spring Boot?

Spring boot - How to specify different location for rotated tomcat log file