具有类路径的Spring Boot可执行Jar [英] Spring Boot Executable Jar with Classpath
问题描述
我正在使用Spring Boot构建与企业软件系统交互的软件系统.我的系统依赖于该企业系统中的某些jar和* .ini文件,因此我无法将所有依赖项打包在Maven中.我希望能够将Spring Boot作为具有嵌入式Tomcat的可执行Jar运行.我还希望能够通过命令行设置类路径.像这样:
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
但是,-classpath和-jar无法共存.我已经尝试过"-Dloader.path".它能够加载文件夹下的所有jar文件,但不能加载其他文件,例如文件夹中的* .ini文件.
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.
那么有没有办法使-classpath与带有嵌入式Tomcat的Spring可执行jar一起使用?
So is there a way we can make -classpath to work with an Spring executable jar with embedded Tomcat?
在此先感谢您的帮助.
推荐答案
如果只想添加外部库,则可以使用loader.path
属性.
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.
让我们假设您正在从类de.app.Application
初始化Spring Boot上下文.您的MANIFEST.MF
应该如下所示:
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/
然后您可以简单地使用java -jar MyApp.jar
启动应用.
And the you can simply start your app with java -jar MyApp.jar
.
有关MANIFEST.MF的更多信息,请参见使用清单文件:基础知识.
For more information about the MANIFEST.MF please see Working with Manifest Files: The Basics.
这篇关于具有类路径的Spring Boot可执行Jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!