【发布时间】:2016-02-13 21:29:07
【问题描述】:
我在回答这个问题Specify system property to Maven project 时包含了 maven 属性插件。为了能够从文件中设置我的数据库属性(并在测试环境中使用 maven 参数覆盖它)。但是,如果我尝试通过访问其中一个属性
System.getProperty("mysql.url") 例如 null 返回。如何从设置属性目标访问属性集。
private void initializeDatabaseConfiguration() {
url = System.getProperty("mysql.url");
con = DriverManager.getConnection(url, username, password);
}
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/config.properties</file>
</files>
<properties>
<property>
<name>mysql.url</name>
<value>${mysql.url}</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
【问题讨论】:
标签: java maven properties-file