Maven资源过滤

简介: 直接上图,一目了然配置文件web.xml文件配置pom.xml文件配置 4.0.

直接上图,一目了然

配置文件

配置文件

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>

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

执行效果

目录
相关文章
|
7月前
|
XML Java Maven
Maven资源拷贝插件和常用依赖
Maven资源拷贝插件和常用依赖
151 0
|
4月前
|
Java Maven 数据安全/隐私保护
Maven高级-本地仓库访问私服配置及私服资源上传与下载
Maven高级-本地仓库访问私服配置及私服资源上传与下载
280 0
|
11月前
|
Java 定位技术 Maven
qqwry.dat输出乱码问题及maven打包后资源文件大小不一致的问题
qqwry.dat输出乱码问题及maven打包后资源文件大小不一致的问题
121 0
|
Java Maven
Maven项目获取资源文件路径并读取资源文件内容
Maven项目获取资源文件路径并读取资源文件内容
216 0
Maven项目获取资源文件路径并读取资源文件内容
|
Java 数据库连接 Maven
mybatis maven资源导出失败的问题
mybatis maven资源导出失败的问题
|
Java Maven
Maven资源过滤问题
解决Maven资源过滤问题
123 0
Maven资源过滤问题
|
Java Maven
Maven 资源导出问题
在 Maven 导出资源,默认约定资源文件夹 resources 中的资源会自动导出,但是有时除了 resources 中包含资源,我们还有可能将资源文件放在其他目录下,此时 Maven 就不会帮我们导出这些资源,需要在 pom.xml 文件下增加如下配置。
|
1月前
|
Java Maven
手把手教你搭建Maven项目
手把手教你搭建Maven项目
31 0

推荐镜像

更多