带有类路径的 Spring Boot 可执行 Jar [英] Spring Boot Executable Jar with Classpath

查看:47
本文介绍了带有类路径的 Spring Boot 可执行 Jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个软件系统来与企业软件系统进行交互,使用 Spring Boot.我的系统依赖于该企业系统中的一些 jars 和 *.ini 文件,因此我无法在 Maven 中打包所有依赖项.我希望能够将 Spring Boot 作为带有嵌入式 Tomcat 的 Executable 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


更新

如果您还需要从类路径中读取其他文件,您必须创建/更改应用程序的清单文件.

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: your-lib/

您可以简单地使用 java -Dloader.path="your-lib/" 启动您的应用程序.-jar MyApp.jar.

有关 MANIFEST.MF 的更多信息,请参阅 使用 Manifest文件:基础.

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

这篇关于带有类路径的 Spring Boot 可执行 Jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆