简体   繁体   English

如何在运行时将其他jar文件添加到spring-boot应用程序?

[英]How to add additional jar file to spring-boot application at runtime?

I built a spring-boot application and make the jar file exectuable. 我构建了一个spring-boot应用程序,并使jar文件可执行。 There is a compileOnly dependency on my project which need to be provided at runtime. 我的项目有一个compileOnly依赖项,需要在运行时提供。 When I run java -jar myApp.jar I will get ClassNotFound exeception which is expected. 当我运行java -jar myApp.jar我将得到预期的ClassNotFound悟性。 But I don't know how to add the additional jar file on java command. 但是我不知道如何在java命令上添加其他jar文件。 I have tried below command: 我试过下面的命令:

java -Dloader.path=/libs/third.jar -jar myApp.jar

but it doesn't work. 但这不起作用。 How can I add /libs/third.jar on my application? 如何在我的应用程序中添加/libs/third.jar

On Unix: java -cp MyApp.jar:./libs/third.jar com.packagename.MainClass 在Unix上: java -cp MyApp.jar:./libs/third.jar com.packagename.MainClass

On Windows: use ; 在Windows上:使用; instead of : and also \\ instead of / 代替:\\代替/

After some searching I figured out the problem with -Dloader.path . 经过一些搜索,我发现了-Dloader.path的问题。 In order to make it works I need to change the project layout to be ZIP which will use PropertiesLauncher . 为了使其工作,我需要将项目布局更改为ZIP ,它将使用PropertiesLauncher Below is the configuration. 以下是配置。

springBoot {
    executable = true
    layout = "ZIP"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM