fig*_*oru 15 java spring external q spring-boot
我想制作独立的Web应用程序.我有一些SpringBoot的问题.
我的应用程序是SpringBoot的一个jar文件.
但我的应用程序通常需要jdbc驱动程序jar.我想为我的应用程序排除jdbc驱动程序jar.我想从lib文件夹中读取库jar.
但是SpringBoot的lib文件夹BOOT-INF/lib是final static.
所以,我想为jdbc驱动程序jar添加外部类路径(lib).
如何在SpringBoot中配置其他类路径.是可用的么?
小智 6
您可以使用该loader.path参数来定义外部lib文件夹的位置。此文件夹下的所有jar都将添加到类路径中。例如,如果您想定义C:\extLib为您的外部lib文件夹,则可以执行以下操作:
java -Dloader.path=/C:/extLib/ -jar aapName.jar
Run Code Online (Sandbox Code Playgroud)
为此,您需要使用PropertiesLauncher。有两种方法可以做到这一点:
选项1
更新项目pom.xml并添加以下标记:
<configuration> <!-- added -->
<layout>ZIP</layout> <!-- to use PropertiesLauncher -->
</configuration
Run Code Online (Sandbox Code Playgroud)
有效的构建标记,更新后的外观如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
选项2
从命令行启动应用程序时,请使用PropertiesLauncher:
java -cp aapName.jar -Dloader.path=/C:/extLib/ org.springframework.boot.loader.PropertiesLauncher
Run Code Online (Sandbox Code Playgroud)
参考:
如何使用jarlauncher将jar添加到SpringBoot类路径
| 归档时间: |
|
| 查看次数: |
25925 次 |
| 最近记录: |