0

Is there any way we can load .yml file using VM argument, like we load .properties file for log4j using -Dlog4j.configuration?

I looked for this but nothing useful found. All solutions are for Spring Boot. But I need to load yaml (from some directory which is not fixed) in an executable jar.

abielita
  • 13,147
  • 2
  • 17
  • 59
The Coder
  • 3,447
  • 7
  • 46
  • 81
  • Possible duplicate of [Parse a yaml file](https://stackoverflow.com/questions/25796637/parse-a-yaml-file) –  Jan 29 '18 at 13:59

1 Answers1

0

Sure. You can get any application parameters with

System.getProperty("my.property");

So if you start your application with

-Dmy.property=path/to/yaml/file

, in your code you can retrieve the value path/to/yaml/file as String and then you can load the file as YAML (for example, with SnakeYAML). The general case of loading YAML from a file is covered in SnakeYaml's documentation.

flyx
  • 35,506
  • 7
  • 89
  • 126