<profiles> <profile> <id>production</id> <properties> <p1>值</p1> </properties> </profile> <profile> <id>development</id> <properties> <p1>值</p1> </properties> </profile> </profiles>
类似与配置的properties文件。只不过这个是在打包时候动态加载的数据
在maven打包时候我们需要指定打包的profile,需要添加-P参数
mvn clean package -Dmaven.test.skip=true -Pdevelopment
如果觉得打包时候使用-P比较烦时候可以使用
<profiles> <profile> <id>production</id> <properties> <p1>值</p1> </properties> </profile> <profile> <id>development</id> <properties> <p1>值</p1> </properties> <activation> //添加对应默认的配置 <activeByDefault>true</activeByDefault> </activation> </profile> </profiles>
还有一种方式可以指定或者是默认想打包那个可以在settings中添加以下默认的配置
<settings> <activeProfiles> <activeProfile>development</activeProfile> </activeProfiles> </settings>
据说可以一次打包两个,没有试过。有兴趣的可以试试
mvn -P development,test clean install 同时执行development和test两个profile