1

I would like to run a Spring Boot application with an extra file (happens to be a css) being on the classpath. I can't touch the jar (the application itself). I can only modify the start script.

I've received a start script with the application::

#! /bin/sh
commandline="java -jar xxx-1.0.0.jar"
commandline="$commandline --spring.config.location=../config/xxx.properties"
commandline="$commandline --logging.config=../config/log4j2.xml"
$commandline

My naive first try was adding a folder with -cp and put the file into that folder. However that is not working because -cp and -jar is not compatible ( nice explanation here: Differences between "java -cp" and "java -jar"? )

Then I found suggestions for using PropertiesLauncher + loader.path which can be seen as a replacement for classpath on the command line ( https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar-property-launcher-features ) . However to use PropertiesLauncher the examples suggested modifying the pom, which I can't do ( Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar? )

What I can do is modifying the shell script.

How should I (if it is possible at all) put the extra file onto the classpath without modifying the Spring Boot application?

riskop
  • 1,693
  • 1
  • 16
  • 34

2 Answers2

3

This also works for me:

#! /bin/sh
commandline="java -cp ../css:xxx-1.0.0.jar org.springframework.boot.loader.JarLauncher"
commandline="$commandline --Spring.config.location=../config/xxx.properties"
commandline="$commandline --logging.config=../config/log4j2.xml"
$commandline

In my case this seems to be simpler than using the PropertiesLauncher.

riskop
  • 1,693
  • 1
  • 16
  • 34
1

I've found this article, which shows how to use PropertiesLauncher without modifying the application (without modifying the pom.xml): https://mash213.wordpress.com/2017/01/05/hack-how-2-add-jars-2-springboot-classpath-with-jarlauncher/

So with the above I can add an extra folder to the classpath and it's indeed working:

#! /bin/sh
commandline="java -Dloader.path=../css -cp xxx-1.0.0.jar org.springframework.boot.loader.PropertiesLauncher"
commandline="$commandline --spring.config.location=../config/xxx.properties"
commandline="$commandline --logging.config=../config/log4j2.xml"
$commandline
riskop
  • 1,693
  • 1
  • 16
  • 34