you can set 'includeSystemScope' to true.

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <includeSystemScope>true</includeSystemScope>
  </configuration>
</plugin>
Answer from allen on Stack Overflow
๐ŸŒ
Medium
thyanmol.medium.com โ€บ using-external-jar-in-springboot-project-7efcf53975b0
Using external jar in springboot project | by Anmol Jain | Medium
November 24, 2023 - Specify the JAR path within the <systemPath> tag. Input the correct group and artifact IDs. Hit and trial may be required to determine the optimal artifact ID for your project. i. You can use the original artifact ID created during project setup.
๐ŸŒ
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 - On the other hand, you will launch the PropertiesLauncher class but adding in the classpath your Spring Boot application. ... java -cp target/myapp-1.0-SNAPSHOT.jar -Dloader.path=/home/user/extlib org.springframework.boot.loader.PropertiesLauncher
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ frameworks โ€บ packaging spring boot apps with external dependencies using maven
Packaging Spring Boot Apps With External Dependencies Using Maven
December 23, 2016 - The application JAR is loaded from lib directory. Logs are being written to logs directory ... Create a distribution directory under src/main/resources. Place the assembly xml, gs-spring-boot- distribution.xml in it.
๐ŸŒ
Medium
medium.com โ€บ @salmankhan_27014 โ€บ incorporating-third-party-jar-files-into-a-spring-boot-application-e42e6eca0ffd
Incorporating Third-Party JAR Files into a Spring Boot Application | by Salman Khan | Medium
February 14, 2023 - In this article, we will explore how to add third-party JAR files to your local Maven repository, and how to incorporate them into your Spring Boot project.
๐ŸŒ
DEV Community
dev.to โ€บ wakeupmh โ€บ building-3rd-party-jars-in-spring-maven-project-4mjh
Building 3rd party JARs in Spring (Maven project) - DEV Community
March 19, 2020 - <dependency> <groupId>com.xpto.lib</groupId> <artifactId>XPTO</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/XPTO.jar</systemPath> </dependency> I was facing this error and about getting crazy before finding this solution. In your pom.xml just add this <includeSystemScope>true</includeSystemScope> like this ยท <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <classifier>exec</classifier> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins>
๐ŸŒ
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
Find elsewhere
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 772683 โ€บ frameworks โ€บ inject-normal-java-class-external
How to inject normal java class from external jar into spring boot application classes (Spring forum at Coderanch)
May 18, 2023 - If you didn't use Maven, Maven ... Boot project and you just want to literally inject it, as Hmai says, you can use the Spring @Autowired annotation if the target is a Spring-managed bean....
๐ŸŒ
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 - -cp <path-to-executable>\executable.jar;<path-to-external-jars>\* org.springframework.boot.loader.PropertiesLauncher ยท An example command line for an application(server) might look like this: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:28555 -Dfile.encoding=UTF8 -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -Xms512m -Xmx2000m -cp D:\Git\app.jar;D:\Git\lib\* org.springframework.boot.loader.PropertiesLauncher
๐ŸŒ
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 โ€บ @anastasios.savvopoulos โ€บ 3-ways-to-load-external-jar-files-to-your-spring-boot-application-f62ec1c232ba
3 ways to load external jar files to your spring boot application | by Anastasios Savvopoulos | Medium
August 14, 2025 - You can simply use an archive tool like 7zip to unzip the files and add your external jar files in the following directory: ... The zip your app again and run with the usual commands that you use or copy it in a container like Tomcat.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 36571940 โ€บ how-to-add-external-jar-proprietary-in-spring-boot
maven - How to add external jar (proprietary) in Spring Boot? - Stack Overflow
May 22, 2017 - mvn install:install-file -Dfile=<your jar file location\file name>.jar -DgroupId=com.kp<groupId> -DartifactId={your custom artifactId} -Dversion={version} -Dpackaging=jar
Top answer
1 of 1
1

It looks like this is possible if the JAR files are copied before starting the Spring application. It feels hackish, but it works. Use at your own risk!

You need two classes, one for bootstrapping the external JARs, which will then start the second via a manually created PropertiesLauncher. The bootstrapping class can be a plain old regular Java class (but it can be a Spring Boot Application too) and only the second class needs to be a SpringBootApplication.

// BootstrapApplication.java
public class BootstrapApplication {
  public static void main(String[] args) {
    System.out.println("Please copy JAR files and press Enter ...");
    System.in.read();

    PropertiesLauncher.main(args);
  }
}
// Application.java
@SpringBootApplication
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

In the gradle file, we can switch back to the default JarLauncher, by removing the bootJar task manifest configuration and applying settings via the springBoot configuration block. mainClass will end up as Start-Class in the MANIFEST.MF file.

// build.gradle
springBoot {
    mainClass = 'com.example.customlauncher.BootstrapApplication'
}

In the properties file for the loader, a new property needs to be set, which points to the real application class. The settings in this file are only picked up by PropertiesLauncher and ignored by JarLauncher. In other words: JarLauncher delegates to Start-Class from the manifest file and PropertiesLauncher delegates to loader.main from its properties file.

# .../resources/loader.properties
loader.path=file:/path/to/dir
loader.main=com.example.customlauncher.Application

Spring (Boot) will first call the main method of BootstrapApplication, as specified in the MANIFEST.MF file (controlled via springBoot configuration block in the build.gradle file). In the implementation of this main method, a new PropertiesLauncher is created with the main class set to the "real" application (i.e. Application).

Executing the application is still done via the same invocation:

java -jar build/libs/customlauncher-0.0.1-SNAPSHOT.jar

Any JAR files added to /path/to/dir after the JVM has started, but before calling PropertiesLauncher#main in BootstrapApplication are then available in the classpath and application context as seen from Application.

Top answer
1 of 2
1

Hi for this question that you have asked

so how we can create a common library folder so that all spring boot application shares the same dependencies from one location

In pom.xml add maven-dependency-plugin with goal as copy-dependencies and under this you can set the output directory for the common library folder

Example

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <phase>install</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                   <outputDirectory>${project.build.directory}/lib</outputDirectory>
                </configuration>
       </execution>
    </executions>
</plugin>

Now you can use the below, to create two jar, one jar with all dependencies(named as appname-exec.jar) included, another jar with only class files (appname.jar)

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <classifier>exec</classifier>
    </configuration>
</plugin>

Now you can use the jar only with class files (appname.jar), because the size will be much lower since it has no dependencies included.

There is one last step needs to be configured in order to work with the jar (appname.jar), is to add the class path entry that is the common location jar and to add your main class name inside tag.

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
    <archive>
        <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>fully.qualified.MainClass</mainClass>
       </manifest>
    </archive>
   </configuration>
</plugin>

Now you can put these three together in you pom.xml under build section as per you project strucure.

2 of 2
0

You can use spring-boot-thin-launcher to build executable and thin Spring Boot jar. It is available for both maven and gradle.

Maven:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot.experimental</groupId>
            <artifactId>spring-boot-thin-layout</artifactId>
            <version>1.0.28.BUILD-SNAPSHOT</version>
        </dependency>
    </dependencies>
</plugin>

Gradle:

plugins {
    //other plugins goes here ...
    id 'org.springframework.boot.experimental.thin-launcher' version '1.0.28.BUILD-SNAPSHOT'
}

You can run Spring Boot thin JAR by command

java -jar my-app-1.0.jar --thin.root=path/to/dependency/jars

You can have look at:

  • Official Plugin Page: https://github.com/spring-projects-experimental/spring-boot-thin-launcher
  • Tutorial: https://www.baeldung.com/spring-boot-thin-jar
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 49403862 โ€บ loading-external-jars-in-spring-boot โ€บ 49403998
java - Loading external jars in spring boot - Stack Overflow
Support project is NOT a gradle project but is given compile time dependencies to the required jars. ... @RestController @RequestMapping("/test") public class CustomService implements WebMvcConfigurer { @RequestMapping(value = "/hello", method = RequestMethod.GET) public @ResponseBody String get() { return "Done!!"; } } ... java -cp Support.jar:Main.jar -Dloader.path=Support.jar -Xbootclasspath/p:alpn-boot-8.1.11.v20170118.jar -Dloader.main=com.abc.app.MyApplication org.springframework.boot.loader.PropertiesLauncher
๐ŸŒ
GitHub
github.com โ€บ markiewb โ€บ spring-boot-propertieslauncher-with-external-jar โ€บ blob โ€บ master โ€บ pom.xml
spring-boot-propertieslauncher-with-external-jar/pom.xml at master ยท markiewb/spring-boot-propertieslauncher-with-external-jar
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> ... <!-- but keep it provided, so that we can still execute this spring-boot application in an IDE -->
Author ย  markiewb