我们通过查询可以了解Maven的基本用法,包括如何编译,打包,以及安装,或者生成文档等等,但是当一个团队共同使用同一个Maven的profile文件时,由于每个人的电脑安装软件,保存资源的路径不同,或者个人电脑与服务器环境不同,就会带来一系列问题:
1 对项目进行打包部署时需要更改pom.xml,以便编译器选择服务器对应的resource文件。如果忘记更改,则造成打包错误。
2 因为每个人的pom.xml不同,导致pom.xml文件无法正常提交,必须手工去掉个人信息。
3 使用eclipse时,可以在Maven设置默认profile, 由于更改pom.xml并不能自动更新默认的profile,造成不必要的麻烦。
下面简要介绍如何通过正确配置profiles来避免以上的问题。
假设我有一个台式机,profile设定为desktop, 还有一个笔记本,profile设定为laptop, 服务器的profile设定为server.
台式机需要采用的resource是application-desktop, 笔记本application-laptop, 服务器application-server
<profiles>
<profile>
<id>desktop</id>
<properties>
<env>desktop</env>
</properties>
</profile>
<profile>
<id>desktop-build</id>
<properties>
<env>server</env>
</properties>
</profile>
<profile>
<id>laptop</id>
<properties>
<env>laptop</env>
</properties>
</profile>
<profile>
<id>laptop-build</id>
<properties>
<env>server</env>
</properties>
</profile>
<profile>
<id>server</id>
<properties>
<env>server</env>
</properties>
</profile>
</profiles>
这样在台式机可以设置desktop为Maven默认值,而desktop-build为编译时的默认值
同样也可以把用户名作为profile的id进行设置,道理是一样的。
Good Luck,
Cheers!