Passing an entire file to JVM arguments

后端 未结 4 637
别跟我提以往
别跟我提以往 2021-02-04 12:21

I have several systems that all need to load the same properties to the JVM. I can use the -D flag to load one property at a time, but i am looking for something that will load

4条回答
  •  日久生厌
    2021-02-04 12:57

    I don't think you can do that via the command line (without some bash hacks, perhaps), but you definitely can do that programatically:

    Simply set one property -DmyPropertiesFile=/your/properties/file.properties and then read that with one of the Properties.load() overloads. After that, System.setProperties(yourProps) should do what you expect.

    Of course, this requires that you can hook this code early enough so that your properties will be available when needed (For instance, if the main() method is yours, this is perfect).

提交回复
热议问题