[英]Running Jar file with external properties
I have jar file that I want to run along with specific properties file.我有要与特定属性文件一起运行的 jar 文件。 I am running following command to execute that jar
我正在运行以下命令来执行该 jar
java –jar –DApp.config.file=local.properties App.jar
With this command I am getting following error使用此命令,我收到以下错误
Could not load properties from class path resource [local.properties]: class path resource [local.properties] cannot be opened because it does not exist
Based on what I read so far if you are passing -jar then you don't have to worry about $CLASSPATH.根据我到目前为止所读到的内容,如果您正在传递 -jar,那么您就不必担心 $CLASSPATH。 Am I missing something here ?
我在这里错过了什么吗?
PS - local.properties and jar files are in same directory. PS - local.properties 和 jar 文件在同一目录中。
The -jar
option specifies the jar file to launch, hence, has to remain right before the naming of the intended jar file: -jar
选项指定要启动的 jar 文件,因此,必须保留在预期 jar 文件的命名之前:
java –DApp.config.file=local.properties –jar App.jar
Don't place other options between –jar
and App.jar
不要在
–jar
和App.jar
之间放置其他选项
您可以使用以下代码片段来访问外部属性文件并运行您的 jar 文件:
java -jar jarname.jar --spring.config.location=/path/to/propertyfile.properties
To load properties as a classpath resource it needs to be on the classpath. 要将属性加载为类路径资源,它必须位于类路径上。 If you're running with
-jar
then everything either needs to be in the jar or you need to play manifest games. 如果使用
-jar
运行,则所有内容都需要放在jar中,或者需要玩清单游戏。
If you want to load properties from an external file then load it as a file, not a classpath resource. 如果要从外部文件加载属性,则将其作为文件而不是类路径资源加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.