Maven,过滤非资源文件

bob*_*bob 8 maven-2

我在几个模块之间共享一个配置文件,我不希望将配置文件烘焙到任何JAR中.

如何对未指定为资源但位于与根​​POM处于同一级别的配置文件夹中的文件进行Maven do(resource)过滤?

Pas*_*ent 6

您可以使用Maven Resources Plugin及其resources:copy-resourcesmojo.从示例中:

复制资源

您可以使用mojo copy-resources复制不在默认maven布局中或未在build/resources元素中声明的资源,并将其附加到阶段

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
Run Code Online (Sandbox Code Playgroud)

另一个选择是使用Maven AntRun插件和Ant过滤功能(例如使用Filter和/或Copy任务),但上面看起来很好.