如何从 Java 属性文件加载设置值? [英] How to load setting values from a Java properties file?
本文介绍了如何从 Java 属性文件加载设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从属性文件中动态加载设置值?
Is there a way for me to dynamically load a setting value from a properties file?
我的意思是,而不是硬编码到 build.sbt
I mean, instead of hardcoding into build.sbt
name := "helloWorld"
有一些 application.properties
文件和
name=helloWorld
然后,在 build.sbt
文件中,有 name := application.properties["name"]
(最后一个例子纯粹是示意图,但我希望这个想法很清楚)
And then, in the build.sbt
file, have name := application.properties["name"]
(last example is purely schematic, but I hope the idea was clear)
推荐答案
您可以创建一个设置键来保存从文件中读取的属性.
You can create a setting key which holds properties read from a file.
import java.util.Properties
val appProperties = settingKey[Properties]("The application properties")
appProperties := {
val prop = new Properties()
IO.load(prop, new File("application.properties"))
prop
}
name := appProperties.value.getProperty("name")
这篇关于如何从 Java 属性文件加载设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文