Is there a way for me to dynamically load a setting value from a properties file?
I mean, instead of hardcoding into build.sbt
name := "helloWorld"
Have some application.properties
file with
name=helloWorld
And then, in the build.sbt
file, have name := application.properties["name"]
(last example is purely schematic, but I hope the idea was clear)
Each key and its corresponding value in the property list is a string. The Properties file can be used in Java to externalize the configuration and to store the key-value pairs. The Properties. load() method of Properties class is convenient to load .
To get information from the properties file, create the properties file first. Now, let's create the java class to read the data from the properties file. Now if you change the value of the properties file, you don't need to recompile the java class. That means no maintenance problem.
To set properties in a Java Properties instance you use the setProperty() method.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With