【发布时间】:2016-06-27 02:29:57
【问题描述】:
我正在尝试根据配置文件通过 maven 设置一些系统环境变量。 所以我的 pom 代码是
<profile>
<id>dev</id>
<activation>
<property>
<name>com.xxx.profile</name>
<value>dev</value>
</property>
</activation>
<properties>
<db-url>jdbc:postgresql://abc</db-url>
<db-username>xxx</db-username>
<db-pwd>yy</db-pwd>
</properties>
</profile>
所以当我构建项目时,我会 mvn clean install -Dcom.xxx.profile=dev
在代码中,我有
String urlDB = System.getProperty("db-url");
String username = System.getProperty("db-username");
String password = System.getProperty("db-pwd");
但是当我运行它时,所有这些变量都是空的。
System.getProperty("com.xxx.profile") 确实给出了正确的答案......
想法?
【问题讨论】:
标签: java maven-2 pom.xml profiles