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
  • 12,662
  • 2
  • 16
  • 55
The Coder
  • 2,749
  • 4
  • 39
  • 68
  • 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
  • 29,987
  • 6
  • 79
  • 110