I have a spring boot 3 project that is packaged as a jar file with all the dependencies in it (fat jar). When I run the jar file using the command java -jar MyApp.jar then the application starts so that works. I want to run the jar file, with plugin possibility by adding extra jars in production environments.
From what I understand is that when you run the jar file the directories lib and config are added to the classpath. These folders being subfolders of the folder where the jar file is located.
MyApp.jar
| -lib
| -config
I have done this and yet the application.property file in the config folder is not detected and extra jars in the lib folder aren't loaded either.
Is it possible to solve this and if so how?
To run a Spring Boot 3 fat JAR with external libraries in a lib
directory and configuration files in a config
directory, follow these steps:
Directory Structure: Ensure your structure looks like this:
Run the Application: Use the following command to start your application, ensuring to include the external libraries and configuration folder:
java -cp "MyApp.jar:lib/*" org.springframework.boot.loader.WarLauncher --spring.config.additional-location=file:./config/
Explanation:
-cp "MyApp.jar:lib/*"
: Sets the classpath to include your JAR and all JARs in the lib
folder.
--spring.config.additional-location=file:./config/
: Tells Spring to load configuration files from the config
directory.
Make sure to adjust the path separator if you're on Windows (;
instead of :
).