繁体   English   中英

使用外部属性运行 Jar 文件

[英]Running Jar file with external properties

我有要与特定属性文件一起运行的 jar 文件。 我正在运行以下命令来执行该 jar

java –jar –DApp.config.file=local.properties App.jar

使用此命令,我收到以下错误

Could not load properties from class path resource [local.properties]: class path resource [local.properties] cannot be opened because it does not exist

根据我到目前为止所读到的内容,如果您正在传递 -jar,那么您就不必担心 $CLASSPATH。 我在这里错过了什么吗?

PS - local.properties 和 jar 文件在同一目录中。

-jar选项指定要启动的 jar 文件,因此,必须保留在预期 jar 文件的命名之前:

java –DApp.config.file=local.properties –jar App.jar

不要在–jarApp.jar之间放置其他选项

您可以使用以下代码片段来访问外部属性文件并运行您的 jar 文件:

java -jar jarname.jar --spring.config.location=/path/to/propertyfile.properties

要将属性加载为类路径资源,它必须位于类路径上。 如果使用-jar运行,则所有内容都需要放在jar中,或者需要玩清单游戏。

如果要从外部文件加载属性,则将其作为文件而不是类路径资源加载。

暂无
暂无

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

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