Maven resource filtering for single file

2020-02-26 03:36发布

In pom.xml I have defined :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>xml</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

and

<resources>
    <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
    </resource>
</resources>

Now the problem is all xml files are not filtered. Is there any possible way to filter single xml file?

标签: xml spring maven
3条回答
仙女界的扛把子
2楼-- · 2020-02-26 03:43

Something like this works fine for me:

    <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>my_file.xml</include>
            </includes>
        </resource>
    </resources>

This documentation helps me: Apache Maven - Filtering

查看更多
Fickle 薄情
3楼-- · 2020-02-26 03:48

I don't know why Gabor's solution did not work, but I managed to solve this way:

Firstly I removed nonFilteredFileExtension tag:

<nonFilteredFileExtension>xml</nonFilteredFileExtension>

Then modified my resources this way:

<resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <includes>
        <include>**/myxml.xml</include>
    </includes>
</resource>

<resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
        <include>**/*.xml</include>
    </includes>
</resource>

Now my single xml file is filtered and other is leaved untouched by filter.

查看更多
▲ chillily
4楼-- · 2020-02-26 04:00

For the resource tag you can used includes and excludes. Just define simply a mask, which fits your single file only. See http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Sample:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>**/yoursinglefile.xml</include>
        </includes>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>
查看更多
登录 后发表回答