Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

My application is one jar file from SpringBoot.

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

But SpringBoot lib folder is BOOT-INF/lib is final static. So, I want to add external classpath (lib) for the jdbc driver jar.

How to configure additional classpath in SpringBoot. Is it available?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
170 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[3] html - How to create even cell spacing within a

548k questions

547k answers

4 comments

86.3k users

...