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!