您的位置:首页 > 其它

Maven 的构建之 pom文件一些属性分析

2017-08-06 20:31 190 查看
1 Maven 属性:

属性的引用很简单,即属性名,Maven有很多内置属性,如{basedir},表示项目根目录但是用的最多的还是自定义属性。

自定义属性也很简单,在<properties/>标签里面定义即可。

2 Maven Profile

不同环境需要不同的配置,所以Maven引入了Profile的概念。Profile的原意是轮廓,Maven就是通过不同的Profile来选择构建项目轮廓。

[html] view plain copy print?<profiles>
<profile>
<id>dev</id>
<properties>
<db.driver>…</db.driver>
<db.url>…</db.url>
<db.username>…</db.username>
<db.password>…</db.password>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<db.driver>…</db.driver>
<db.url>…</db.url>
<db.username>…</db.username>
<db.password>…</db.password>
</properties>
</profile>
</profiles>
<profiles>
<profile>
<id>dev</id>
<properties>
<db.driver>...</db.driver>
<db.url>...</db.url>
<db.username>...</db.username>
<db.password>...</db.password>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<db.driver>...</db.driver>
<db.url>...</db.url>
<db.username>...</db.username>
<db.password>...</db.password>
</properties>
</profile>
</profiles>


Maven通过命令行激活Profile,使用-P参数,如mvn clean install -Ptest

我们可以使用如下方式来选择默认激活的Profile的方式:

<activation>

<activeByDefault>true</activeByDefault>

</activation>

当存在其它激活方式的时候,默认激活失效。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: