??????????????????У??????????????????????????????????????????maven????????????????????????????????????????
????1????????????£?

????2??????????????
????1?????pom.xml????????????????
<profiles>
<!-- ????/??????????????? -->
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!--??????????dev???????? -->
</activation>
</profile>
<!-- ???????? -->
<profile>
<id>product</id>
<properties>
<env>product</env>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<filters> <!-- ??????? filter -->
<filter>src/main/filters/filter-${env}-env.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
????3??filter-test-env.properties????
????jdbc.url=jdbc:mysql://192.168.120.220:3306/testdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
????jdbc.username=testuser
????jdbc.password=123456
????4??db.properties????
????url=${jdbc.url}
????username=${jdbc.username}
????password=${jdbc.password}
????5??java??????????????£?
package com.jumei.mvntest;
import java.io.FileNotFoundException;
import java.util.ResourceBundle;
public class test {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
ResourceBundle res = ResourceBundle.getBundle("db");
String username=res.getString("username");
System.out.println(username);
}
}
????????????????????dev???????????????????????????-Pproduct????
?????磺mvn compile -Pproduct??mvn package -Pproduct