Maven资源过滤

直接上图,一目了然

配置文件

配置文件

web.xml文件配置

web.xml配置

pom.xml文件配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>aaa</groupId>
    <artifactId>aaa</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>aaa Maven Webapp</name>
    <url>http://maven.apache.org</url>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <profiles>

        <!--开发环境-->
        <profile>
            <id>dev</id>
            <!--在这里定义property就相当于在property文件中定义属性一样-->
            <properties>
                <env>dev</env>
            </properties>
            <build>
                <filters>
                    <!--每个property文件都需要写一个filter-->
                    <filter>src/main/env/dev/dubbo.properties</filter>
                    <filter>src/main/env/dev/mysql.properties</filter>
                    <filter>src/main/env/dev/sms.properties</filter>
                </filters>
            </build>
        </profile>

        <!--测试环境-->
        <profile>
            <id>test</id>
            <properties>
                <env>test</env>
            </properties>
            <build>
                <filters>
                    <filter>src/main/env/test/dubbo.properties</filter>
                    <filter>src/main/env/test/mysql.properties</filter>
                    <filter>src/main/env/test/sms.properties</filter>
                </filters>
            </build>
        </profile>

        <!--线上环境-->
        <profile>
            <id>product</id>
            <properties>
                <env>product</env>
            </properties>
            <build>
                <filters>
                    <filter>src/main/env/product/dubbo.properties</filter>
                    <filter>src/main/env/product/mysql.properties</filter>
                    <filter>src/main/env/product/sms.properties</filter>
                </filters>
            </build>
        </profile>
    </profiles>


    <!--配置所有profile都公用的信息-->
    <build>

        <finalName>aaa</finalName>

        <!--指定资源目录  配置是否启用资源过滤(就是是否启用占位符替换)-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>


        <!--通过这个插件可以对web.xml文件进行资源过滤-->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <filtering>true</filtering>
                            <directory>src/main/webapp</directory>
                            <includes>
                                <include>**/web.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

执行效果(以开发环境示例)

执行效果

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值