【问题标题】:How to filter specific file with maven resource filtering如何使用 Maven 资源过滤过滤特定文件
【发布时间】:2012-12-18 08:44:29
【问题描述】:

我的 spring+maven 项目有 .properties 和 .xml 资源文件。我只想为 .properties 设置过滤,不包括所有 spring xml 配置。这很简单:

    <resource>
        <filtering>true</filtering>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
            <exclude>**/*.properties</exclude>
        </excludes>
    </resource>
    <resource>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/resources</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>

但现在我想对一个具体的 xml 文件应用过滤器,比如 env-config.xml。那么问题是如何对所有 .properties 文件和一个特定的 xml 文件应用过滤器?

【问题讨论】:

  • 我相信在第一个资源元素中您打算编写 .properties。对吧?

标签: spring maven resources filtering


【解决方案1】:

尝试再添加一个资源元素

<resource>
    <filtering>true</filtering>
    <directory>${basedir}/src/main/resources</directory>
    <includes>
        <include>path/to/file.xml</include>
    </includes>
</resource>

不确定它是否有效,我现在没有 maven。

【讨论】:

  • 它确实有效。请注意,这将使 maven-eclipse-plugin(如果您正在使用它),因为它不处理指向同一目录的 &lt;resource/&gt;-s 的多个定义。
  • 注意,如果你想从你的项目的根目录添加文件,你需要指定一个空的标签而不是/(它是相对于POM的位置)
猜你喜欢
  • 1970-01-01
  • 2016-08-16
  • 1970-01-01
  • 1970-01-01
  • 2011-11-20
  • 2015-10-25
  • 2020-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多