直接上代码:
pom 文件:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.habakkuk.demo
mvn_filter_demo
1.0-SNAPSHOT
dev
filters/dev.properties
pro
filters/pro.properties
true
src/main/resources
资源目录:
filters 目录是 需要过滤的配置,resource目录里面的配置文件 使用 @name@ 作为占位符。
测试代码:
public class M {
public static void main(String[] args) throws IOException {
Properties properties=new Properties();
properties.load(M.class.getResourceAsStream("/p.properties"));
System.out.println("result:"+properties.getProperty("p.need.change"));
}
}
默认直接运行 并没有替换 , 是因为没有 active 的profile
可以再pom 文件里面 指定 也可以 再 mvn 命令 中指定 -P 参数。
再idea 中可以 直接勾选