Maven项目中通过profile定义使不同环境使用不同配置信息

profile可以让我们定义一系列的配置信息,然后指定其激活条件。这样我们就可以定义多个profile,然后每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同配置信息的效果。比如说,我们可以通过profile定义在jdk1.5以上使用一套配置信息,在jdk1.5以下使用另外一套配置信息;或者有时候我们可以通过操作系统的不同来使用不同的配置信息,比如windows下是一套信息,linux下又是另外一套信息,等等。

下面是不同操作系统使用不同配置信息的示例代码,pom.xml文件中添加:

 1 <profiles>
 2     <profile>
 3         <id>dev</id>
 4         <activation>
 5             <activeByDefault>true</activeByDefault>
 6             <os>
 7                 <family>Windows</family>
 8             </os>
 9         </activation>
10         <properties>
11             <filter.path>srcmain
esourcesconfig-dev.properties</filter.path>
12         </properties>
13     </profile>
14     <profile>
15         <id>production</id>
16         <activation>
17             <activeByDefault>false</activeByDefault>
18             <os>
19                 <family>Linux</family>
20             </os>
21         </activation>
22         <properties>
23             <filter.path>srcmain
esourcesconfig.properties</filter.path>
24         </properties>
25     </profile>
26 </profiles>
原文地址:https://www.cnblogs.com/guyezhai/p/5649880.html