How to configure an extra classpath in SpringBoot?

I want to make a standalone web application. I have a problem with SpringBoot.

My application is a single jar file from SpringBoot.

But for my application, a jdbc driver jar was usually needed. I want to exclude jdbc jar for my application. I want to read the jar library from the lib folder.

But the libb folder SpringBoot BOOT-INF/lib is final static .

So, I want to add an external classpath (lib) for the jdbc jar driver.

How to set up an extra classpath in SpringBoot. Is it available?

+7
source share
2 answers

You can link to this link below: spring boot:

https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar-property-launcher-features

You can use the loader.path property to locate the lib folder

+7
source

You can use the loader.path parameter to determine the location for the external lib folder. All banks in this folder will be added to the classpath. For example, if you want 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 PropertiesLauncher. There are two ways to do this:

Option 1

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

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

Effective build tag, post update looks like this:

 <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 PropertiesLauncher when starting the application from the command line:

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

Links: https://mash213.wordpress.com/2017/01/05/hack-how-2-add-jars-2-springboot-classpath-with-jarlauncher/

0
source

Source: https://habr.com/ru/post/1012159/


All Articles