Spring Boot Executable Jar with Classpath

user1670498 :

I am building a software system to interact with an enterprise software system, using Spring Boot. My system depends on some jars and *.ini files from that enterprise system, so I cannot pack all dependencies in Maven. I would like to be able to run Spring Boot as Executable Jar with embedded Tomcat. I would also like to be able to set the classpath via the command line. So something like:

java -classpath /home/sleeper/thirdparty/lib -jar MyApp.jar

However, -classpath and -jar cannot co-exist. I have tried "-Dloader.path". It was able to load all the jar files under the folder, but not other things, like *.ini files in the folder.

So is there a way we can make -classpath to work with an Spring executable jar with embedded Tomcat?

Thank you in advance for all the help.

Paul Wasilewski :

If you just want add external libraries you can use the loader.path property.

java -Dloader.path="your-lib/" -jar your-app.jar

UPDATE

If you also need to read additional files from the classpath you have to create/change the manifest file of your application.

Lets assume that your are initializing your Spring Boot context from the class de.app.Application. Your MANIFEST.MF should looks as follows:

Manifest-Version: 1.0
Main-Class: de.app.Application
Class-Path: /home/sleeper/thirdparty/lib/

And the you can simply start your app with java -jar MyApp.jar.

For more information about the MANIFEST.MF please see Working with Manifest Files: The Basics.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=453955&siteId=1