Maven Resources Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
=Overview=
=Overview=


The plugin, whose configuration is declared in the <resources> section of the <build> block, it is executed at the  
By default, the plugin reads the configuration declared in the <resources> section of the <build> block and automatically executes its resources:resources goal at the "[[Maven_Concepts_-_Lifecycle#process-resources|process-resources]]" lifecycle phase.





Revision as of 18:43, 2 March 2018

External

Internal

Overview

By default, the plugin reads the configuration declared in the <resources> section of the <build> block and automatically executes its resources:resources goal at the "process-resources" lifecycle phase.


Variables can be replaced during when the resource plugin executes. For more details on how to specify variables to be replaced, see Maven Filtering and Property Substitution.

Resources

Variable Substitution in Resource Files

Set "filtering" to true as follows, and all variables will be substituted on copy:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

For more details on how to specify the variables to be replaced, see:

Maven Filtering and Property Substitution

Copy Text Files in target and Final Artifact

  <build>
        ...
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.txt</include>
                </includes>
            </resource>
        </resources>
        ...
  </build>

This will copy all text files found under src/main/java into ./target/classes and make them available in the class path.


If you specify just the <directory>src/main/java</directory> resource under <resources>, this will remove all other implicit resources, including <directory>src/main/resources</directory> so if you were relying on that (for log4j.xml or whatever else) you will need to add it explicitly, as shown in the example below.

  <build>
        ...
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.txt</include>
                </includes>
            </resource>
        </resources>
        ...
  </build>

Java Source Code Filtering

Last time I tried to filter java source code with the following <resources> declaration, it did not work. Clarify why.

    <build>
        <resources>
            <resource>
                <directory>src/main/java/io/novaordis/gld/extensions/jboss/datagrid</directory>
                <includes>
                    <include>JBossDatagrid7Service.java</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>