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 -->
</configuration>

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

<build> 
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>  <!-- added -->
                <layout>ZIP</layout> <!-- to use PropertiesLauncher -->
            </configuration>
        </plugin>
    </plugins>
</build>

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

References:
How to add jars to SpringBoot classpath with jarlauncher

Answer from giftednewbie on Stack Overflow
🌐
Spring
docs.spring.io › spring-boot › docs › 1.0.1.RELEASE › reference › htmlsingle
Spring Boot Reference Guide
Spring Boot provides a number of “Starter POMs” that make easy to add jars to your classpath. Our sample application has already used spring-boot-starter-parent in the parent section of the POM. The spring-boot-starter-parent is a special starter that provides useful Maven defaults.
🌐
M*A*S*H
mash213.wordpress.com › 2017 › 01 › 05 › hack-how-2-add-jars-2-springboot-classpath-with-jarlauncher
Hack – How 2 add jars 2 springboot classpath with JarLauncher ?
January 5, 2017 - 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 'org.springframework.boot.loader.JarLauncher' # and your additional classes will be picked up by springboot
🌐
Spring
docs.spring.io › spring-boot › docs › 1.1.2.RELEASE › reference › html › getting-started-first-application.html
10. Developing your first Spring Boot application
Spring Boot provides a number of “Starter POMs” that make easy to add jars to your classpath. Our sample application has already used spring-boot-starter-parent in the parent section of the POM. The spring-boot-starter-parent is a special starter that provides useful Maven defaults.
Top answer
1 of 7
15

On Linux:

Copyjava -cp MyApp.jar:/home/sleeper/thirdparty/lib -Dloader.main=myMainApplicationClass org.springframework.boot.loader.PropertiesLauncher

On Windows:

Copyjava -cp MyApp.jar;/home/sleeper/thirdparty/lib -Dloader.main=myMainApplicationClass org.springframework.boot.loader.PropertiesLauncher

This will avoid messing with the manifest or the Spring Boot Maven plugin configuration as in the other answers. It will launch your app with the PropertiesLauncher, which allows you to specify the main class in loader.main. As mentioned earlier, for some reason if you use PropertiesLauncher with loader.path, it will not add resource files to the classpath. This works around the issue by using -cp instead of -jar.

EDIT As mentioned by Pianosaurus in the comment, use ":" instead of ";" as separator in the classpath on Linux

2 of 7
14

If you just want add external libraries you can use the loader.path property.

Copyjava -Dloader.path="your-lib/" -jar your-app.jar

UPDATE

If you also need to read additional files from the classpath you have to create/change the manifest file of your application.

Lets assume that your are initializing your Spring Boot context from the class de.app.Application. Your MANIFEST.MF should looks as follows:

CopyManifest-Version: 1.0
Main-Class: de.app.Application
Class-Path: your-lib/

And the you can simply start your app with java -Dloader.path="your-lib/" -jar MyApp.jar.

For more information about the MANIFEST.MF please see Working with Manifest Files: The Basics.

🌐
Masterspringboot
masterspringboot.com › home › how to use an external jar in a spring boot application
How to use an external JAR in a Spring Boot application - Masterspringboot
December 19, 2022 - There are two simple ways to do that: the simplest one is to add the property on the command line. Also, you will not launch the Spring Boot application in the usual format (java -jar application). On the other hand, you will launch the PropertiesLauncher class but adding in the classpath your ...
🌐
Spring
docs.spring.io › spring-boot › specification › executable-jar › nested-jars.html
Nested JARs :: Spring Boot
Any dependencies that are required when running embedded but are not required when deploying to a traditional web container should be placed in WEB-INF/lib-provided. Spring Boot Loader-compatible jar and war archives can include additional index files under the BOOT-INF/ directory. A classpath.idx file can be provided for both jars and wars, and it provides the ordering that jars should be added to the classpath.
Find elsewhere
🌐
Spring
docs.spring.io › spring-boot › docs › current › reference › html › executable-jar.html
The Executable Jar Format
April 19, 2024 - Any dependencies that are required when running embedded but are not required when deploying to a traditional web container should be placed in WEB-INF/lib-provided. Spring Boot Loader-compatible jar and war archives can include additional index files under the BOOT-INF/ directory. A classpath.idx file can be provided for both jars and wars, and it provides the ordering that jars should be added to the classpath.
🌐
Baeldung
baeldung.com › home › java › jvm › ways to add jars to classpath in java
Ways to Add JARs to Classpath in Java | Baeldung
August 19, 2025 - Java applications often depend on several bundles of external code called JARs. Here is a listing and explanation of each of the major ways to add these JARs to your application's classpath.
🌐
LinuxTut
linuxtut.com › en › 817185c65881ec611277
[JAVA] How to add a classpath in Spring Boot
October 30, 2018 - <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>ZIP</layout> </configuration> </plugin> Next, regarding the settings related to the classpath to be added, there are several setting methods. They are listed in descending order of priority. You can add the classpath with -Dloader.path at startup. ... By the way, I ran it like -Dloader.path = [path] after -jar and it didn't work, so I was worried for a while.
🌐
Codevomit
codevomit.xyz › bootlog › blog › how-to-provide-spring-boot-fat-jar
CodeVomit
November 26, 2016 - Manifest-Version: 1.0 Implementation-Title: bootlog Implementation-Version: 0.0.1 Archiver-Version: Plexus Archiver Built-By: merka Implementation-Vendor-Id: xyz.codevomit Spring-Boot-Version: 1.4.0.RELEASE Implementation-Vendor: CodeVomit Productions Main-Class: org.springframework.boot.loader.JarLauncher Start-Class: xyz.codevomit.bootlog.BootlogApplication Spring-Boot-Classes: BOOT-INF/classes/ Spring-Boot-Lib: BOOT-INF/lib/ Created-By: Apache Maven 3.3.3 Build-Jdk: 1.8.0_65 Implementation-URL: http://projects.spring.io/spring-boot/bootlog/ The important entries are Main-Class and Start-Class. The first is the actual main class called by the JVM. In this default case, the JarLoader is only able to locate and load classes inside BOOT-INT and JARs inside the lib directory. With this loader there's no way to add external JARs to the classpath.
🌐
Medium
medium.com › @Jeef › dynamically-loading-libraries-into-a-springboot-application-at-run-time-80639ee5aab
Dynamically loading libraries into a SpringBoot application at run time | by Jeff Stein | Medium
October 17, 2019 - bootJar { enabled = false } jar { enabled = true } ... Additionally the application uses the PropertiesLauncher which allows one to add additional Jars to the classpath at startup.
🌐
Medium
medium.com › @mak0024 › provide-external-jars-for-the-spring-boot-application-c65821ce6368
Provide external jars for the Spring Boot application | by AM | Medium
December 19, 2023 - To make it work for a Windows service we might have to need to adjust the path a little due to the wildcard character(*) in the jsl.ini. -Djmx.port=26086 -Dfile.encoding=UTF-8 -Xms512m -Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -cp "app.jar;lib\*" org.springframework.boot.loader.PropertiesLauncher
Top answer
1 of 4
1

If you're using maven to build your application, it runs in the netbeans IDE, but you'll need to define a plugin in your maven pom.xml in order to include all of the required .jars in your final .jar to make it executable.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>yourmainpackagename.YourMainClass</mainClass>
                        </transformer>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.handlers</resource>
                        </transformer>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.schemas</resource>
                        </transformer>
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>

This approach uses the maven shade plugin. You could also be using the maven assembly plugin, be prepared to face nasty bugs though :p

cheers.

2 of 4
0

If you are compiling using Netbeans IDE (with proper build path) then build artifact (the jar) and the lib/ would be in dist directory.

cd into the ${project-root}/dist directory and then run :

java -jar XXXXX.jar

The dependency on the libraries must be already taken care of in MANIFEST by Netbeans.

PS: See the generated README in the dist directory.

🌐
GitHub
github.com › spring-projects › spring-plugin › issues › 73
How to use external jar in springboot project · Issue #73 · spring-projects/spring-plugin
October 23, 2019 - java -jar springboot-sample.war -classpath /software/git/test-spring-plugin/okm-spring-plugins/target/
Author   spring-projects
🌐
Medium
medium.com › @gurram.naveen › external-jars-with-springboot-app-4be422afdd35
Augment with external jars in Spring Boot app | by Naveen Gurram | Medium
September 27, 2024 - with the above I was able to load it into classpath but not without limitations, if this jar we are augmenting has any other dependencies and unless that jar is a another fat jar and even if the existing spring boot has those dependencies, reason being this is loaded as first classloader and that will need to have all the dependencies. Since this is an jar file, I can extract it and add required libraries and put the jar back.
🌐
Medium
medium.com › @kouomeukevin › demystifying-the-classpath-in-spring-boot-why-and-how-to-use-it-c76ec31d8986
Demystifying the Classpath in Spring Boot: Why and How to Use it | by Kevin Kouomeu | Medium
April 6, 2024 - During compilation, these files are transformed into bytecode (.class files) and placed on the classpath for the runtime environment to utilize. Resource Directories These directories contain static resources, including configuration files (e.g., properties files), images, and JavaScript files. Spring Boot employs conventions to automatically scan these directories when resolving resource URLs. Dependency JAR Files JAR files encapsulate third-party libraries and classes that are essential…
🌐
Spring
docs.spring.io › spring-boot › docs › 1.4.x › reference › html › getting-started-installing-spring-boot.html
10. Installing Spring Boot
If you are new to Java development, or if you just want to experiment with Spring Boot you might want to try the Spring Boot CLI first, otherwise, read on for “classic” installation instructions. You can use Spring Boot in the same way as any standard Java library. Simply include the appropriate spring-boot-*.jar files on your classpath.