Joey Yi Zhao
Joey Yi Zhao

Reputation: 42520

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

I built a spring-boot application and make the jar file exectuable. There is a compileOnly dependency on my project which need to be provided at runtime. When I run java -jar myApp.jar I will get ClassNotFound exeception which is expected. But I don't know how to add the additional jar file on java command. 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?

Upvotes: 0

Views: 1443

Answers (2)

Shubham Agrawal
Shubham Agrawal

Reputation: 308

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

On Windows: use ; instead of : and also \ instead of /

Upvotes: 1

Joey Yi Zhao
Joey Yi Zhao

Reputation: 42520

After some searching I figured out the problem with -Dloader.path. In order to make it works I need to change the project layout to be ZIP which will use PropertiesLauncher. Below is the configuration.

springBoot {
    executable = true
    layout = "ZIP"
}

Upvotes: 0

Related Questions