maven-profile的多环境配置方式之一,实际案例笔记

"该博客介绍了如何在Maven中设置多个环境Profile,包括dev、prod、test和testjndi,用于区分不同环境的配置。在资源处理部分,通过excludes排除了特定环境的文件夹,并使用filtering对${env}
摘要由CSDN通过智能技术生成
<profiles>
    <profile>
        <!--不同环境Profile的唯一id-->
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>
    <profile>
        <id>testjndi</id>
        <properties>
            <env>testjndi</env>
        </properties>
    </profile>
</profiles>

 <resources>
    <resource>
        <directory>src/main/resources</directory>
        <!--打包时先排除掉三个文件夹-->
        <excludes>
            <exclude>dev/*</exclude>
            <exclude>prod/*</exclude>
            <exclude>test/*</exclude>
            <exclude>testjndi/*</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources/${env}</directory>
        <filtering>true</filtering>
    </resource>
</resources>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.2</version>
    <configuration>
        <warSourceExcludes>src/main/resources/META-INF/**</warSourceExcludes>
        <packagingExcludes>WEB-INF/classes/META-INF/**</packagingExcludes>
        <webResources>
            <resource>
                <directory>src/main/resources/META-INF/resources</directory>
                <filtering>true</filtering>
                <targetPath>/</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>

在这里插入图片描述
注意在勾选对应环境后,需要刷新一下pom后再重新启动项目,这里的项目使用的是Tomcat的方式启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悠闲的线程池

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值