概述
在项目开发时,会有各种开发环境,mac、linux、windows,然后开发环境、测试环境、预发布环境、生产环境,各个数据库等都不一样。
那么不可能每次发布时都要去修改对应的数据库配置,等其他相关配置。
可以用 maven 的 profiles 来实现不同环境的相关配置。
使用
1、在项目中创建下面几个文件,并在中填写自己的配置 key=value
src/main/filters/filter-dev.properties
src/main/filters/filter-test.properties
src/main/filters/filter-production.properties
2、在 pom.xml
中添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<!-- 环境 --> <build> <defaultGoal>compile</defaultGoal> <finalName>${project.artifactId}</finalName> <filters> <filter>src/main/filters/filter-${env}.properties</filter> </filters> <resources> <!-- 只过滤properties文件中得属性 --> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> <include>**/*.sql</include> </includes> </resource> </resources> </build> <profiles> <!-- 开发环境,默认激活 --> <profile> <id>dev</id> <properties> <env>dev</env> </properties> <activation> <!--默认启用 --> <activeByDefault>true</activeByDefault> </activation> </profile> <!-- 生产环境 --> <profile> <id>production</id> <properties> <env>production</env> </properties> </profile> <!-- 测试环境 --> <profile> <id>test</id> <properties> <env>test</env> </properties> </profile> </profiles> |
原创文章,转载请注明: 转载自LoserZhao – 诗和远方[ http://www.loserzhao.com/ ]
本文链接地址: http://www.loserzhao.com/bigdata/maintenance/maven-profiles.html
文章的脚注信息由WordPress的wp-posturl插件自动生成
0 条评论。