如何为 JVM 设置自定义系统变量以访问属性文件?

how to set custom system variable for JVM to access properties file?

我需要从我使用变量 -Dapp.conf=/path/to/config.properties 设置的位置读取 config.properties 文件,并在启动我的应用程序时将其设置为数据源。 文件应该位于文件系统中的任何位置。 怎么做?

您可以如下加载 properties 文件:

Properties p = new Properties();
try (Reader reader = new FileReader(System.getProperty("app.conf"))) {
    p.load(reader);
}

加载后,您可以使用 properties 实例来设置数据源配置。