.properties file
Closed this issue · 2 comments
Hi, please document how to load a .properties file from the root of a JAR file (shadowJar).
I was finally able to get it to work, but this seems rather contrived -- creating a Properties object, loading in a stream, then using that object to supply the PropsPropertySource
:
.addSource(PropsPropertySource(
Properties().apply {
load(Config::class.java.getClassLoader().getResourceAsStream("v.properties"))
}
))
Earlier I tried loading a file directly -- but all of the following lines fail with Could not detect parser for file extension '.properties' - available parsers are yml, yaml
(My .yaml config files work fine). They all seemed to fail whether trying to access a file inside the JAR (like a resourcestream) or an external file.
// all result in Could not detect parser for file extension '.properties' - available parsers are yml, yaml
.addResourceSource("v.properties")
.addPropertySource(PropertySource.path(executionPath.resolve("v.properties")))
.addFileSource(executionPath.resolve("v.properties").toFile(), optional = true)
Please help, .properties file parsing is built-in but there are no examples of how to load one? Hoplite is a terrific tool but sometimes seems there are so many options that finding the "easy way" is not so easy!
I think you just need to use /v.properties and not just v.properites.
This issue was due to not adding mergeServiceFiles()
to my shadowJar task. I guess the YAML module was overwriting the CORE module so that .props/.properties files weren't recognized, that's why the error said it could not detect a parser:
Could not detect parser for file extension '.properties' - available parsers are yml, yaml
I have submitted a PR to add this important instruction to the README. It's quite tricky because the project works fine during development from the IDE, it only fails when packaged into a fat JAR file.
(and yes, the slash is required for a file in the root of the JAR file: addResourceSource("/v.properties")
)