美文网首页maven
Maven resource 配置中include与exclud

Maven resource 配置中include与exclud

作者: fanderboy | 来源:发表于2020-06-28 15:06 被阅读0次

    Maven resource 中的<include>与<exclude>用于包含或排除某一文件目录下的文件是否是工程资源的。
    若<include>与<exclude>划定的范围存在冲突,则以<include>配置为准。
    多数情况下,使用<include>和<exclude>是为了配合<filtering>实现替换文件中的变量的需要。

    include的作用:
    使用include可以规定指定路径下的xml包括properties文件在编译期,将文件指定的@profiles.active@替换掉。
    例如:XXX.properties中我们使用@profiles.active@来代表激活的偏好。那么在Maven编译时,就会将@profiles.active@替换成真正的偏好。

    exclude的作用:
    使用exclude可以规定指定路径下的配置文件,在编译后打包时不被放入资源路径里。

    注:
    如果<include>与<exclude>划定的范围存在冲突时
    并不会执行<exclude>,而是执行<include>
    include的使用示例:

               <resource>
                    <directory>src/main/resources</directory>
                    <!-- 是否替换@xx@表示的maven properties属性值 -->
                    <filtering>true</filtering>
                    <!-- 过滤指定路径下的配置文件属性 -->
                   <!-- 
                        注:
                            1、include可以配置多个路径,但路径不要重复,也别包含
                            2、*与**/*意义不同,*指resource路径下,并不包含resource子文件夹下的文件, **/*指resource路径及其子路径下所有文件。
                        <include>*</include>
                        <include>**/*</include>  
                        <include>*.xml</include>
                        <include>**/*.xml</include>
                     -->
                    <includes>
                        <include>application.properties</include>
                        <include>application-dev.properties</include>
                        <include>application-test.properties</include>
                        <include>application-prod.properties</include>
                        <include>application-pressure.properties</include>
                        <include>bootstrap.properties</include>
                    </includes>
                </resource>
    

    exclude的使用示例:

               <resource>
                    <directory>src/main/resources</directory>
                    <!-- 
                    不过滤指定路径下的文件:此路径下的指定文件打包时,将不被放入resource中。
                    -->   
                    <excludes>
                        <exclude>application*.properties</exclude>
                        <exclude>bootstrap*.properties</exclude>
                    </excludes>
                </resource>
    

    注:exclude里filtering的true、false值详解:

    true与false相同点:
                        exclude规定路径下的文件不被打包。
    true与false不同点:
                        true: 不在exclude排除路径下的文件执行include过滤。
                        false:不在exclude排除路径下的文件不执行include过滤。
    

    include和exclude里filtering总结:

    filtering为true:
    include:替换指定文件中@xx@表示的maven properties属性值
    exclude:替换指定文件以外@xx@表示的maven properties属性值
    filtering为false:
    include:不替换指定文件中@xx@表示的maven properties属性值
    exclude:不替换指定文件以外@xx@表示的maven properties属性值
    以上<include>与<exclude>划定的范围存在冲突,则以<include>配置为准。
    

    相关文章

      网友评论

        本文标题:Maven resource 配置中include与exclud

        本文链接:https://www.haomeiwen.com/subject/skqwfktx.html