We had a scenario where we were using the JarLauncher of springboot but had to add additional jars to classpath.
i.e. we would launch the springboot app using the following command
java -jar fat_app.jar
Since springboot when using JarLaunhcer , ignores -classpath or -cp argument of java, our attempt to add a jar via -cp argument fails.
Solution as of now is to modify the pom.xml and change to Properties launcher i.e. change pom.xml as follows
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- added --> <layout>ZIP</layout> <!-- to use PropertiesLaunchar --> </configuration> </plugin> </plugins> </build>
But we DID NOT want to do the above.
We wanted to add a jar, without changing the pom.xml
i.e. continue using the JAR Launcher.
When we use the jar launcher i.e. run via the following command
java -jar fat_app.jar # The main class in JAR manifest # is set to 'org.springframework.boot.loader.JarLauncher'
The solution is to go the old java way and provide the main class yourself:
i.e. the solution is
java \ -cp fat_app.jar \ -Dloader.path=<path_to_your_additional_jars> \ org.springframework.boot.loader.PropertiesLauncher # It should work now, even though the main class in manifest # of fat_app.jar is set to '
' # and your additional classes will be picked up by springboot
#Thanks to my ex colleague @Dapeng for the idea