Maven资源筛选用于单个文件

时间:2021-04-23 17:15:01

In pom.xml I have defined :

砰的一声。我定义的xml:

<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文件都没有被过滤。有可能过滤单个xml文件吗?

3 个解决方案

#1


16  

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

我不知道为什么Gabor的方法不起作用,但我设法这样解决了:

Firstly I removed nonFilteredFileExtension tag:

首先,我删除了非filteredfileextension标签:

<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.

现在,我的单个xml文件被过滤了,而其他文件则没有被过滤。

#2


11  

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

对于资源标记,您可以使用包含和排除。只需定义一个掩码,它只适合您的单个文件。参见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>

#3


3  

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

这个文档帮助我:Apache Maven - filter

#1


16  

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

我不知道为什么Gabor的方法不起作用,但我设法这样解决了:

Firstly I removed nonFilteredFileExtension tag:

首先,我删除了非filteredfileextension标签:

<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.

现在,我的单个xml文件被过滤了,而其他文件则没有被过滤。

#2


11  

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

对于资源标记,您可以使用包含和排除。只需定义一个掩码,它只适合您的单个文件。参见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>

#3


3  

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

这个文档帮助我:Apache Maven - filter