【发布时间】:2016-08-15 07:47:53
【问题描述】:
我需要从我用变量-Dapp.conf=/path/to/config.properties 设置的位置读取config.properties 文件,并在我启动我的应用程序时将其设置为数据源。
文件应位于文件系统中的任何位置。
如何做到这一点?
【问题讨论】:
标签: java jvm properties-file system-variable
我需要从我用变量-Dapp.conf=/path/to/config.properties 设置的位置读取config.properties 文件,并在我启动我的应用程序时将其设置为数据源。
文件应位于文件系统中的任何位置。
如何做到这一点?
【问题讨论】:
标签: java jvm properties-file system-variable
您可以加载您的properties 文件,如下所示:
Properties p = new Properties();
try (Reader reader = new FileReader(System.getProperty("app.conf"))) {
p.load(reader);
}
加载后,您可以使用 properties 实例来设置数据源配置。
【讨论】:
runner maven 属性中使用 Idea 插件中的 Jetty 启动我的应用程序,在 Environment variables 中我设置了 -Dapp.conf=/path/to/config.properties。