Maven Resources Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
* http://maven.apache.org/plugins/maven-resources-plugin/
* http://maven.apache.org/plugins/maven-resources-plugin/
* http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
* http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
=Internal=
* [[Maven#Plugins|Maven]]
* [[Maven Timestamp Support]]


=Overview=
=Overview=
Line 8: Line 13:
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]].
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]].


=Internal=
=Resources=
 


* [[Maven#Plugins|Maven]]
* [[Maven Timestamp Support]]


=Variable Substitution in Resource Files=
=Variable Substitution in Resource Files=

Revision as of 02:34, 22 December 2016

External

Internal

Overview

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.

Warning! 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:

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