利用Maven高效管理项目解决方案

13 篇文章 0 订阅
9 篇文章 0 订阅

我们通过查询可以了解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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值