by BehindJava

How to configure additional classpath in SpringBoot

Home » springboot » How to configure additional classpath in SpringBoot

In this tutorial we are going to learn about configuring the additional classpath in SpringBoot.

Firstly you can use the loader.path parameter to define a location for an external lib folder. All jars under this folder will be added to the classpath. For example, if you’d like to define C:\extLib as your external lib folder, you can do the following:

java -Dloader.path=/C:/extLib/ -jar aapName.jar

For this to work, you need to use the PropertiesLauncher. There are two ways to do that:

Option 1

Update the project pom.xml and add the following tag:

<configuration>  <!-- added -->
  <layout>ZIP</layout> <!-- to use PropertiesLauncher -->

Effective build tag, the post-update looks like below:

            <configuration>  <!-- added -->
                <layout>ZIP</layout> <!-- to use PropertiesLauncher -->

Option 2

Use the PropertiesLauncher when launching the application from the commandline:

java -cp aapName.jar -Dloader.path=/C:/extLib/ org.springframework.boot.loader.PropertiesLauncher